[Test] // behaviour test public void Create_When_entity_is_created_Then_it_makes_calls_to_repository_and_unit_of_work() { // Arrange var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeTypeService.Create(planeTypeDTOToCreate); // Assert. Just behaviour A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).MustHaveHappenedOnceExactly(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustHaveHappenedOnceExactly(); }
[Test] // behaviour test public void Create_When_entity_is_invalid_Then_it_makes_no_calls_to_repository_and_unit_of_work() { // Arrange var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeTypeService.Create(planeTypeDTOToCreate)); // Assert. Just behaviour A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.PlaneTypeRepository).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).MustNotHaveHappened(); A.CallTo(() => unitOfWorkFake.SaveChanges()).MustNotHaveHappened(); }
public void Create_When_entity_is_invalid_Then_bad_request_exception_is_thrown() { // Arrange var planeTypeMock = new PlaneType() { Id = 2, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).Returns(planeTypeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysInValidValidator); // Act + Assert var exception = Assert.Throws <BadRequestException>(() => planeTypeService.Create(planeTypeDTOToCreate), ""); Assert.AreEqual(exception.Message, "Is Invalid"); }
public async Task SubmitCreate(string model, int places, int carCap) { Model.PlaneType temp = new Model.PlaneType(); temp.Model = model; temp.Places = (places); temp.CarryCapacity = (carCap); await pts.Create(temp); this.Frame.Navigate(typeof(PlaneType)); }
public void Create_When_entity_is_created_Then_new_plane_type_with_new_id_is_returned() { // Arrange var planeTypeMock = new PlaneType() { Id = 1, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeDTOToCreate = new PlaneTypeDTO() { Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var expectedPlaneTypeDTO = new PlaneTypeDTO() { Id = 1, Model = "AAABBBCCC", Seats = 500, Carrying = 400 }; var planeTypeRepositoryFake = A.Fake <IPlaneTypeRepository>(); A.CallTo(() => planeTypeRepositoryFake.Create(A <PlaneType> ._)).Returns(planeTypeMock); var unitOfWorkFake = A.Fake <IUnitOfWork>(); A.CallTo(() => unitOfWorkFake.Set <PlaneType>()).Returns(planeTypeRepositoryFake); var planeTypeService = new PlaneTypeService(unitOfWorkFake, AlwaysValidValidator); // Act var result = planeTypeService.Create(planeTypeDTOToCreate); // Assert Assert.AreEqual(expectedPlaneTypeDTO.Id, result.Id); Assert.AreEqual(expectedPlaneTypeDTO.Model, result.Model); Assert.AreEqual(expectedPlaneTypeDTO.Seats, result.Seats); Assert.AreEqual(expectedPlaneTypeDTO.Carrying, result.Carrying); }
async void Create() { await _planeTypeService.Create(PlaneType); await LoadPlaneTypes().ConfigureAwait(false); }
async void Create() { await PlaneTypeservice.Create(PlaneType); await LoadEntity().ConfigureAwait(false); }