コード例 #1
0
        //获取类名

        public RoleService(IDbContext context) : base(context)
        {
            moduleApp       = new ModuleService(context);
            moduleButtonApp = new ModuleButtonService(context);
            moduleFieldsApp = new ModuleFieldsService(context);
            itemsApp        = new ItemsDataService(context);
        }
コード例 #2
0
        public void Should_UpdateItem_When_InputParametersAreValid()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges());

            var updatedItemDto = new ItemDto()
            {
                Id   = 1,
                Name = "Bread updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };


            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto);


            //Assert
            AssertHelper.AssertAll(
                () => saveObject.Id.Should().Be(1),
                () => saveObject.Name.Should().Be("Bread updated"),
                () => saveObject.NextReplenishmentDate.Should().BeSameDateAs(new DateTime(2020, 10, 10)),
                () => saveObject.ReplenishmentPeriod.Should().Be(4)
                );
        }
コード例 #3
0
        public void Should_ReturnASuccessResponse_When_InputParametersAreValid()
        {
            //Arrange
            var itemDto = BuildFirstItemDtoWithoutId();
            var item    = BuildFirstItemWithoutId();

            MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto))
            .Returns(item);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Add(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var result = ItemsDataService.AddItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", itemDto);



            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeTrue(),
                () => result.ErrorMessage.Should().BeNull()
                );
        }
コード例 #4
0
        public void Should_ReturnAnErrorResponse_When_ItemRepositoryThrowsAnException()
        {
            //Arrange
            var itemDto = BuildFirstItemDtoWithoutId();
            var item    = BuildFirstItemWithoutId();

            MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto))
            .Returns(item);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Add(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges())
            .Throws(new Exception());


            //Act
            var result = ItemsDataService.AddItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", itemDto);


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occurred while creating item")
                );
        }
コード例 #5
0
        public void Should_AddItem_When_InputParametersAreValid()
        {
            //Arrange
            var itemDto = BuildFirstItemDtoWithoutId();
            var item    = BuildFirstItemWithoutId();

            MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto))
            .Returns(item);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Add(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var result = ItemsDataService.AddItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", itemDto);


            //Assert
            AssertHelper.AssertAll(
                () => saveObject.Id.Should().Be(0),
                () => saveObject.Name.Should().Be("Bread"),
                () => saveObject.NextReplenishmentDate.Should().BeSameDateAs(new DateTime(2020, 10, 06)),
                () => saveObject.ReplenishmentPeriod.Should().Be(1)
                );
        }
コード例 #6
0
        public void Should_CheckForUserIdEmptyBeforeAllOtherMethodCalls_When_UserIdIsEmpty()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());

            var updatedItemDto = new ItemDto()
            {
                Id   = 1,
                Name = "Bread updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };

            //Act
            var result = ItemsDataService.UpdateItem(string.Empty, updatedItemDto);


            //Assert
            AssertHelper.AssertAll(
                () => ItemsRepositoryMock.Verify(x => x.All(), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.Update(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #7
0
        public void Should_ReturnResponseWithCorrectItemName_When_OneItemNameOfThisUserContainSearchWord()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var filteredItem  = BuildFirstItem();
            var filteredItems = new List <Item>()
            {
                filteredItem
            };

            var filteredItemNameDto  = BuildFirstItemNameDto();
            var filteredItemNameDtos = new List <ItemNameDto>()
            {
                filteredItemNameDto
            };

            MapperMock
            .Setup(c => c.ProjectTo(
                       It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                       null,
                       It.Is <Expression <Func <ItemNameDto, object> >[]>(x => x.Length == 0)))
            .Returns(filteredItemNameDtos.AsQueryable());

            //Act
            var result = ItemsDataService.GetItemsNames("d", "ab70793b-cec8-4eba-99f3-cbad0b1649d0");

            //Assert
            result.Data.First().Name.Should().Be("Bread");
        }
コード例 #8
0
        public void Should_ReturnAnErrorResponse_When_UserIdIsEmptyString()
        {
            //Arrange
            var itemDto = BuildFirstItemDtoWithoutId();
            var item    = BuildFirstItemWithoutId();

            MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto))
            .Returns(item);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Add(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var result = ItemsDataService.AddItem(string.Empty, itemDto);


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occurred while creating item")
                );
        }
コード例 #9
0
        public void Should_CheckForUserIdEmptyBeforeOtherMethodCalls_When_UserIdIsEmptyString()
        {
            //Arrange
            var itemDto = BuildFirstItemDtoWithoutId();
            var item    = BuildFirstItemWithoutId();

            MapperMock.Setup(c => c.Map <ItemDto, Item>(itemDto))
            .Returns(item);

            var saveObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Add(It.IsAny <Item>()))
            .Callback <Item>((obj) => saveObject = obj);

            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var result = ItemsDataService.AddItem(string.Empty, itemDto);


            //Assert
            AssertHelper.AssertAll(
                () => MapperMock.Verify(x => x.Map <ItemDto, Item>(It.IsAny <ItemDto>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.Add(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #10
0
        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()
                );
        }
コード例 #11
0
        public void Should_NotDeleteAnyItem_When_CurrentUserDoesNotHaveItemWithThisId()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var deleteObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()))
            .Callback <Item>((obj) => deleteObject = obj);

            ItemsRepositoryMock.Setup(x => x.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(5, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => ItemsRepositoryMock.Verify(x => x.Delete(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #12
0
        public void Should_ReturnErrorResponse_When_RepositorySaveChangesThrowsAnException()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges()).Throws(new Exception());

            var updatedItemDto = new ItemDto()
            {
                Id   = 1,
                Name = "Bread updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };


            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto);


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occurred while updating item")
                );
        }
コード例 #13
0
        public void Should_NotUpdateAnyItemInTheDb_When_AnotherUserHasThisItem()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());

            var updatedItemDto = new ItemDto()
            {
                Id   = 5,
                Name = "Cake updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };


            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto);


            //Assert
            AssertHelper.AssertAll(
                () => ItemsRepositoryMock.Verify(x => x.All(), Times.Once()),
                () => ItemsRepositoryMock.Verify(x => x.Update(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #14
0
        public void Should_ReturnErrorResponse_When_AnotherUserHasThisItem()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());

            var updatedItemDto = new ItemDto()
            {
                Id   = 5,
                Name = "Cake updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };


            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", updatedItemDto);


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("Current user does not have item with id 5")
                );
        }
コード例 #15
0
        public void Should_ReturnErrorResponse_When_UserIdIsNull()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var deleteObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()))
            .Callback <Item>((obj) => deleteObject = obj);

            ItemsRepositoryMock.Setup(x => x.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(1, null);


            //Assert
            AssertHelper.AssertAll(
                () => response.IsSuccess.Should().BeFalse(),
                () => response.ErrorMessage.Should().Be("An error occurred while deleting item")
                );
        }
コード例 #16
0
        public void Should_NotDeleteAnyItem_When_UserIdIsNull()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var deleteObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()))
            .Callback <Item>((obj) => deleteObject = obj);

            ItemsRepositoryMock.Setup(x => x.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(1, null);


            //Assert
            AssertHelper.AssertAll(
                () => ItemsRepositoryMock.Verify(x => x.Delete(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #17
0
        public void Should_ReturnErrorResponse_When_CurrentUserDoesNotHaveItemWithThisId()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var deleteObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()))
            .Callback <Item>((obj) => deleteObject = obj);

            ItemsRepositoryMock.Setup(x => x.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(5, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => response.IsSuccess.Should().BeFalse(),
                () => response.ErrorMessage.Should().Be("Current user does not have item with id 5")
                );
        }
コード例 #18
0
        public void Should_ReturnErrorResponse_When_AnExceptionOccursInProjectToMethod()
        {
            //Arrange
            var allItems = new List <Item>().AsQueryable();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var filteredItems = new List <Item>();

            MapperMock.Setup(c => c.ProjectTo(
                                 It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                                 null,
                                 It.Is <Expression <Func <ItemNameDto, object> >[]>(x => x.Length == 0)))
            .Throws(new Exception());

            //Act
            var result = ItemsDataService.GetItemsNames("B", "ab70793b-cec8-4eba-99f3-cbad0b1649d0");

            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occured while getting items names."),
                () => result.Data.Should().BeNull()
                );
        }
コード例 #19
0
        public void Should_ReturnErrorResponse_When_NoItemsExist()
        {
            //Arrange
            var allItems = new List <Item>().AsQueryable();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var filteredItems    = new List <Item>();
            var filteredItemDtos = new List <ItemDto>();

            MapperMock
            .Setup(c => c.ProjectTo(
                       It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                       null,
                       It.Is <Expression <Func <ItemDto, object> >[]>(x => x.Length == 0)))
            .Returns(filteredItemDtos.AsQueryable());


            //Act
            var result = ItemsDataService.GetItem(2, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => result.Data.Should().BeNull(),
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("Current user does not have item with id 2")
                );
        }
コード例 #20
0
        public void Should_ReturnErrorResponse_When_CurrentUserDoesNotHaveItemWithThisId()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var filteredItems    = new List <Item>();
            var filteredItemDtos = new List <ItemDto>();

            MapperMock
            .Setup(c => c.ProjectTo(
                       It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                       null,
                       It.Is <Expression <Func <ItemDto, object> >[]>(x => x.Length == 0)))
            .Returns(filteredItemDtos.AsQueryable());


            //Act
            var result = ItemsDataService.GetItem(2, "925912b0-c59c-4e1b-971a-06e8abab7848");


            //Assert
            AssertHelper.AssertAll(
                () => result.Data.Should().BeNull(),
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("Current user does not have item with id 2")
                );
        }
コード例 #21
0
        public void Should_CheckForItemDtoNullBeforeAllOtherMethodCalls_When_ItemDtoIsNull()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());

            var updatedItemDto = new ItemDto()
            {
                Id   = 1,
                Name = "Bread updated",
                NextReplenishmentDate = new DateTime(2020, 10, 10),
                ReplenishmentPeriod   = 4
            };

            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", null);


            //Assert
            AssertHelper.AssertAll(
                () => ItemsRepositoryMock.Verify(x => x.All(), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.Update(It.IsAny <Item>()), Times.Never()),
                () => ItemsRepositoryMock.Verify(x => x.SaveChanges(), Times.Never())
                );
        }
コード例 #22
0
        public void Should_CallDeletemethodWithCorrectItem_When_InputParametersAreValid()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var deleteObject = new Item();

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()))
            .Callback <Item>((obj) => deleteObject = obj);

            ItemsRepositoryMock.Setup(x => x.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(1, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => deleteObject.Id.Should().Be(1),
                () => deleteObject.Name.Should().Be("Bread"),
                () => deleteObject.NextReplenishmentDate.Should().BeSameDateAs(new DateTime(2020, 10, 06)),
                () => deleteObject.ReplenishmentPeriod.Should().Be(1),
                () => deleteObject.UserId.Should().Be("ab70793b-cec8-4eba-99f3-cbad0b1649d0")
                );
        }
コード例 #23
0
        public void Should_ReturnSuccessResponseWithNoEntries_When_ThereAreNoItemsInRepository()
        {
            //Arrange
            InitializeMocksWithEmptyCollection();

            //Act
            var result = ItemsDataService.GetItemsNames("B", "ab70793b-cec8-4eba-99f3-cbad0b1649d0");

            //Assert
            AssertHelper.AssertAll(
                () => result.Data.Count().Should().Be(0),
                () => result.IsSuccess.Should().BeTrue(),
                () => result.ErrorMessage.Should().BeNull()
                );
        }
コード例 #24
0
        public void Should_ReturnErrorResponse_When_UserIdIsEmpty()
        {
            //Arrange
            InitializeMocksWithEmptyCollection();

            //Act
            var result = ItemsDataService.GetItemsNames("B", string.Empty);

            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occured while getting items names."),
                () => result.Data.Should().BeNull()
                );
        }
コード例 #25
0
        public void Should_ReturnErrorResponse_When_SearchWordIsNull()
        {
            //Arrange
            InitializeMocksWithEmptyCollection();


            //Act
            var result = ItemsDataService.GetItemsNames(null, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");

            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occured while getting items names."),
                () => result.Data.Should().BeNull()
                );
        }
コード例 #26
0
        public void Should_ReturnSuccessResponseWithNoEntries_When_UserIdDoesNotExist()
        {
            //Arrange
            InitializeMocksWithEmptyCollection();


            //Act
            var result = ItemsDataService.GetItemsNames("Re", "1111");


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeTrue(),
                () => result.ErrorMessage.Should().BeNull(),
                () => result.Data.Count().Should().Be(0)
                );
        }
コード例 #27
0
        public void Should_ReturnSuccessResponse_When_InputParametersAreValid()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Delete(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var response = ItemsDataService.DeleteItem(1, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => response.IsSuccess.Should().BeTrue(),
                () => response.ErrorMessage.Should().BeNull()
                );
        }
コード例 #28
0
        public void Should_ReturnErrorResponse_When_ItemDtoIsNull()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            ItemsRepositoryMock.Setup(c => c.Update(It.IsAny <Item>()));
            ItemsRepositoryMock.Setup(c => c.SaveChanges());


            //Act
            var result = ItemsDataService.UpdateItem("ab70793b-cec8-4eba-99f3-cbad0b1649d0", null);


            //Assert
            AssertHelper.AssertAll(
                () => result.IsSuccess.Should().BeFalse(),
                () => result.ErrorMessage.Should().Be("An error occurred while updating item")
                );
        }
コード例 #29
0
        public void Should_ReturnResponseWithCorrectItemsNamesOfAllItemsOfThisUser_When_SearchWordIsEmptyString()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var firstFilteredItem  = BuildFirstItem();
            var secondFilteredItem = BuildSecondItem();
            var thirdFilteredItem  = BuildThirdItem();
            var filteredItems      = new List <Item>()
            {
                firstFilteredItem, secondFilteredItem, thirdFilteredItem
            };

            var firstFilteredItemNameDto  = BuildFirstItemNameDto();
            var secondFilteredItemNameDto = BuildSecondItemNameDto();
            var thirdFilteredItemNameDto  = BuildThirdItemNameDto();
            var filteredItemNameDtos      = new List <ItemNameDto>()
            {
                firstFilteredItemNameDto, secondFilteredItemNameDto, thirdFilteredItemNameDto
            };

            MapperMock
            .Setup(c => c.ProjectTo(
                       It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                       null,
                       It.Is <Expression <Func <ItemNameDto, object> >[]>(x => x.Length == 0)))
            .Returns(filteredItemNameDtos.AsQueryable());

            //Act
            var result = ItemsDataService.GetItemsNames(string.Empty, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");

            //Assert
            AssertHelper.AssertAll(
                () => result.Data.First().Name.Should().Be("Bread"),
                () => result.Data.Skip(1).First().Name.Should().Be("Cheese"),
                () => result.Data.Skip(2).First().Name.Should().Be("Biscuits")
                );
        }
コード例 #30
0
        public void Should_ReturnResponseWithCorrectItem_When_CurrentUserHasItemWithThisId()
        {
            //Arrange
            var allItems = BuildItemsCollection();

            ItemsRepositoryMock.Setup(x => x.All()).Returns(allItems);

            var filteredItem  = BuildSecondItem();
            var filteredItems = new List <Item>()
            {
                filteredItem
            };

            var filteredItemDto  = BuildSecondItemDto();
            var filteredItemDtos = new List <ItemDto>()
            {
                filteredItemDto
            };

            MapperMock
            .Setup(c => c.ProjectTo(
                       It.Is <IQueryable <Item> >(x => ItemsTestHelper.HaveTheSameElements(filteredItems, x)),
                       null,
                       It.Is <Expression <Func <ItemDto, object> >[]>(x => x.Length == 0)))
            .Returns(filteredItemDtos.AsQueryable());


            //Act
            var result = ItemsDataService.GetItem(2, "ab70793b-cec8-4eba-99f3-cbad0b1649d0");


            //Assert
            AssertHelper.AssertAll(
                () => result.Data.Id.Should().Be(2),
                () => result.Data.Name.Should().Be("Cheese"),
                () => result.Data.NextReplenishmentDate.Should().BeSameDateAs(new DateTime(2020, 10, 08)),
                () => result.Data.ReplenishmentPeriod.Should().Be(2)
                );
        }