public void TestBuildSuccess() { var customer = mCustomerBuilder.Build("Test Customer"); Assert.Equal("Test", customer.Firstname); Assert.Equal("Customer", customer.Lastname); }
public void Finish_Should_Finish_An_Existing_Job() { // arrange CustomerBuilder customerBuilder = new CustomerBuilder(); VehicleBuilder vehicleBuilder = new VehicleBuilder(); MaintenanceJobBuilder maintenanceJobBuilder = new MaintenanceJobBuilder(); Customer customer = customerBuilder .Build(); Vehicle vehicle = vehicleBuilder .WithCustomerId(customer.CustomerId) .Build(); MaintenanceJob sut = maintenanceJobBuilder .WithCustomer(customer) .WithVehicle(vehicle) .Build(); DateTime actualStartTime = maintenanceJobBuilder.StartTime.AddMinutes(30); DateTime actualEndTime = maintenanceJobBuilder.EndTime.AddMinutes(15); string notes = $"Mechanic notes {maintenanceJobBuilder.Id}"; // act sut.Finish(actualStartTime, actualEndTime, notes); // assert Assert.Equal(maintenanceJobBuilder.Id, sut.Id); Assert.Equal(maintenanceJobBuilder.StartTime, sut.StartTime); Assert.Equal(maintenanceJobBuilder.EndTime, sut.EndTime); Assert.Equal(customer, sut.Customer); Assert.Equal(vehicle, sut.Vehicle); Assert.Equal(maintenanceJobBuilder.Description, sut.Description); Assert.Equal(actualStartTime, sut.ActualStartTime.Value); Assert.Equal(actualEndTime, sut.ActualEndTime.Value); Assert.Equal(notes, sut.Notes); Assert.Equal("Completed", sut.Status); }
public void Plan_Should_Create_A_New_Job() { // arrange CustomerBuilder customerBuilder = new CustomerBuilder(); VehicleBuilder vehicleBuilder = new VehicleBuilder(); MaintenanceJobBuilder maintenanceJobBuilder = new MaintenanceJobBuilder(); Customer customer = customerBuilder .Build(); Vehicle vehicle = vehicleBuilder .WithCustomerId(customer.CustomerId) .Build(); MaintenanceJob sut = maintenanceJobBuilder .WithCustomer(customer) .WithVehicle(vehicle) .Build(); // act // sut.Plan() is called by the Testdata Builder // assert Assert.Equal(maintenanceJobBuilder.Id, sut.Id); Assert.Equal(maintenanceJobBuilder.StartTime, sut.StartTime); Assert.Equal(maintenanceJobBuilder.EndTime, sut.EndTime); Assert.Equal(customer, sut.Customer); Assert.Equal(vehicle, sut.Vehicle); Assert.Equal(maintenanceJobBuilder.Description, sut.Description); Assert.Null(sut.ActualStartTime); Assert.Null(sut.ActualEndTime); Assert.Null(sut.Notes); Assert.Equal("Planned", sut.Status); }
public void GivenBuilderIsSetAsProxy_WhenBuilding_AnNSubstituteProxyIsReturned() { var builder = new CustomerBuilder().AsProxy(); var proxy = builder.Build(); proxy.CustomerForHowManyYears(Arg.Any <DateTime>()).Returns(100); proxy.CustomerForHowManyYears(DateTime.Now).ShouldBe(100); }
public void GivenBuilderIsSetAsProxy_WhenBuilding_AnNSubstituteProxyIsReturned() { var builder = new CustomerBuilder().AsProxy(); var proxy = builder.Build(); proxy.CustomerForHowManyYears(Arg.Any<DateTime>()).Returns(100); proxy.CustomerForHowManyYears(DateTime.Now).ShouldBe(100); }
public void GivenBuilder_WhenCallingSetExplicitly_ShouldOverrideValues() { var builder = new CustomerBuilder() .Set(x => x.FirstName, "Pi") .Set(x => x.LastName, "Lanningham") .Set(x => x.YearJoined, 2014); var customer = builder.Build(); customer.FirstName.ShouldBe("Pi"); customer.LastName.ShouldBe("Lanningham"); customer.YearJoined.ShouldBe(2014); }
public void GivenBuilderWithMethodCalls_WhenCallingBuildExplicitly_ThenReturnAnObjectWithTheConfiguredParameters() { var builder = new CustomerBuilder() .WithFirstName("Matt") .WithLastName("Kocaj") .WhoJoinedIn(2010); var customer = builder.Build(); customer.FirstName.ShouldBe("Matt"); customer.LastName.ShouldBe("Kocaj"); customer.YearJoined.ShouldBe(2010); }
public void GivenBuilderWithMethodCalls_WhenCallingBuild_ThenReturnAnObjectWithTheConfiguredParameters() { var builder = new CustomerBuilder() .WithFirstName("Matt") .WithLastName("Kocaj") .WhoJoinedIn(2010); var customer = builder.Build(); Assert.That(customer.FirstName, Is.EqualTo("Matt")); Assert.That(customer.LastName, Is.EqualTo("Kocaj")); Assert.That(customer.YearJoined, Is.EqualTo(2010)); }
static void Main(string[] args) { var builder = new CustomerBuilder(); builder.AssignCustomerNumber(321123) .AssignFirstName("Dude") .AssignLastName("McGuy"); //preform action to get/calculate age from elsewhere var age = 22; builder.AssignAge(age); var customer = builder.Build(); Console.WriteLine(customer.ToString()); }
public MaintenanceJob Build() { if (CustomerBuilder == null) { throw new InvalidOperationException("You must specify a customerbuilder using the 'WithCustomerBuilder' method."); } if (VehicleBuilder == null) { throw new InvalidOperationException("You must specify a vehiclebuilder using the 'WithVehicleBuilder' method."); } Customer customer = CustomerBuilder.Build(); Vehicle vehicle = VehicleBuilder.Build(); var job = new MaintenanceJob(JobId); Timeslot plannedTimeslot = Timeslot.Create(StartTime, EndTime); job.Plan(plannedTimeslot, vehicle, customer, Description); return(job); }
public MaintenanceJobPlanned Build() { var customer = CustomerBuilder .Build(); var vehicle = VehicleBuilder .WithOwnerId(customer.Id) .Build(); var job = MaintenanceJobBuilder .WithCustomer(customer) .WithVehicle(vehicle) .Build(); MaintenanceJobPlanned e = new MaintenanceJobPlanned( Guid.NewGuid(), job.Id, job.PlannedTimeslot.StartTime, job.PlannedTimeslot.EndTime, (customer.Id, customer.Name, customer.TelephoneNumber), (vehicle.Id, vehicle.Brand, vehicle.Type), job.Description ); return(e); }
private CustomerDto CustomerToDto(StormCustomer stormCustomer) { CustomerBuilder builder = new CustomerBuilder(); return(builder.Build(stormCustomer)); }
public void BuildWithoutName_ShouldThrowException() { var builder = new CustomerBuilder(); Assert.Throws <InvalidOperationException>(() => builder.Build()); }