Skip to content

Facilitates work with immutable objects, allows changing storage restrictions and prevents importing source objects.

License

Notifications You must be signed in to change notification settings

renanaragao/BuilderImmutableObject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BuilderImmutableObject

Facilitates work with immutable objects, allows changing storage restrictions and prevents importing source objects

How to install with Nuget ?

Install-Package BuilderImmutableObject

What is this repository for?

Library to work with C# immutable objects.

How do I use it?

public class Car
    {
        [Obsolete]
        public Car()
        {

        }

        public Car(string color, int size)
        {
            Color = color;
            Size = size;
        }

        public string Color { get; private set; }
        public int Size { get; private set; }
    }
public class BuilderTest
   {
       private Car _car;

       [SetUp]
       public void SetUp()
       {
           _car = new Car(color: "red", size: 78);
       }

       [Test]
       public void Must_Change_Color_Property()
       {
           var newCar = _car.Set(x => x.Color, "black").Build();

           Assert.AreNotSame(_car, newCar);

           Assert.AreEqual(78, _car.Size);
           Assert.AreEqual("red", _car.Color);

           Assert.AreEqual(78, newCar.Size);
           Assert.AreEqual("black", newCar.Color);
       }

       [Test]
       public void Must_Change_All_Properties()
       {
           var newCar = _car
               .Set(x => x.Color, "black")
               .Set(x => x.Size, 678)
               .Build();

           Assert.AreNotSame(_car, newCar);

           Assert.AreEqual(78, _car.Size);
           Assert.AreEqual("red", _car.Color);

           Assert.AreEqual(678, newCar.Size);
           Assert.AreEqual("black", newCar.Color);
       }
   }
   

About

Facilitates work with immutable objects, allows changing storage restrictions and prevents importing source objects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published