public void Should_CallRepositorySaveChangesAfterUpdateMethod_When_InputParametersAreValid() { //Arrange var allItems = BuildItemsCollection(); ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems); var updatedItemDto = new ItemDto() { Id = 1, Name = "Bread updated", NextReplenishmentDate = new DateTime(2020, 10, 10), ReplenishmentPeriod = 4 }; var sequence = new MockSequence(); ItemsRepositoryMock .InSequence(sequence) .Setup(c => c.Update(It.Is <Item>(x => x.HasTheSameProperties("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto)))); ItemsRepositoryMock.InSequence(sequence).Setup(x => x.SaveChanges()); //Act var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto); //Assert AssertHelper.AssertAll( () => result.IsSuccess.Should().BeTrue(), () => result.ErrorMessage.Should().BeNull() ); }
public void Should_CallSaveMethodAfterDeletemethod_When_InputParametersAreValid() { //Arrange var allItems = BuildItemsCollection(); ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems); var sequence = new MockSequence(); ItemsRepositoryMock.InSequence(sequence).Setup(x => x.Delete(It.IsAny <Item>())); ItemsRepositoryMock.InSequence(sequence).Setup(x => x.SaveChanges()); //Act var response = ItemsDataService.DeleteItem(1, "ab70793b-cec8-4eba-99f3-cbad0b1649d0"); //Assert AssertHelper.AssertAll( () => response.IsSuccess.Should().BeTrue(), () => response.ErrorMessage.Should().BeNull() ); }
public void Should_FirstAddItemThenCallSaveChanges_When_InputParametersAreValid() { //Arrange var itemDto = BuildFirstItemDtoWithoutId(); var item = BuildFirstItemWithoutId(); MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto)) .Returns(item); var sequence = new MockSequence(); ItemsRepositoryMock.InSequence(sequence).Setup(x => x.Add(item)); ItemsRepositoryMock.InSequence(sequence).Setup(x => x.SaveChanges()); //Act var result = ItemsDataService.AddItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", itemDto); //Assert AssertHelper.AssertAll( () => result.IsSuccess.Should().BeTrue(), () => result.ErrorMessage.Should().BeNull() ); }