public async Task GetHiveSectionsAsync_CollectionWithTwoElements_ReturnsCollectionWithTwoElements()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1
                },
                new StoreHive()
                {
                    Id = 2
                }
            };
            List <StoreHiveSection> sectionList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    StoreHiveId = 1
                },
                new StoreHiveSection()
                {
                    StoreHiveId = 2
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(sectionList);
            var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object);

            var list = await service.GetHiveSectionsAsync();

            Assert.Equal(2, list.Count);
        }
        public async Task DeleteHiveSectionAsync_IdPresent_RequestedHiveDeleted()
        {
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> sectionList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, IsDeleted = true
                },
                new StoreHiveSection()
                {
                    Id = 2
                }
            };

            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(sectionList);
            var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object);

            await service.DeleteHiveSectionAsync(1);

            var hiveSections = await service.GetHiveSectionsAsync();

            Assert.DoesNotContain(hiveSections, h => h.Id == 1);
        }
        public async Task CreateHiveSectionAsync_SuccessfulTest(int hiveId, string name, string code)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1
                }
            });
            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var service = new HiveSectionService(context.Object, userContext.Object);
            var request = new UpdateHiveSectionRequest
            {
                Name = name,
                Code = code,
            };

            await service.CreateHiveSectionAsync(hiveId, request);

            var sections = await service.GetHiveSectionsAsync(hiveId);

            Assert.Single(sections);
        }
Exemple #4
0
        public async Task GetHiveSectionsAsync_CollectionWithThreeElements_ThreeElementsListReturned()
        {
            var sections = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 0
                },
                new StoreHiveSection()
                {
                    Id = 1
                },
                new StoreHiveSection()
                {
                    Id = 2
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(sections);
            var service = new HiveSectionService(context.Object, new UserContext());

            var list = await service.GetHiveSectionsAsync();

            Assert.Equal(3, list.Count);
            Assert.Contains(list, h => h.Id == 0);
            Assert.Contains(list, h => h.Id == 1);
            Assert.Contains(list, h => h.Id == 2);
        }
        public async Task GetHiveSectionsAsync_HiveId_ListHiveSectionsListItems(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            // arrange
            var dbSections = fixture.CreateMany <StoreHiveSection>(5).OrderBy(s => s.Id).ToList();

            var hiveId = dbSections[0].StoreHiveId;

            dbSections[3].StoreHiveId = hiveId;
            dbSections[4].StoreHiveId = hiveId;

            context.Setup(s => s.Sections).ReturnsEntitySet(dbSections);

            // act
            var hiveSectionsListItems = await service.GetHiveSectionsAsync(hiveId);

            // assert
            Assert.Equal(3, hiveSectionsListItems.Count);

            Assert.Collection(
                hiveSectionsListItems,
                item => Assert.Equal(dbSections[0].Id, item.Id),
                item => Assert.Equal(dbSections[3].Id, item.Id),
                item => Assert.Equal(dbSections[4].Id, item.Id));
        }
        public async Task GetHiveSectionsAsync_IdPresent_ReturnsAppropriateItems()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1
                },
                new StoreHive()
                {
                    Id = 2
                }
            };
            List <StoreHiveSection> sectionList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    StoreHiveId = 1
                },
                new StoreHiveSection()
                {
                    StoreHiveId = 2
                }
            };

            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(hiveList);
            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(sectionList);
            var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object);

            var list = await service.GetHiveSectionsAsync(1);

            Assert.Single(list);
        }
Exemple #7
0
        public async void GetHiveSectionsAsync_TenEntities_SeccessfulResult([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            Configure(context, fixture);

            var result = await service.GetHiveSectionsAsync();

            result.Should().HaveCount(_section.Count);
        }
Exemple #8
0
        public async Task GetHiveSectionAsync_EmptyListReturned([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service)
        {
            context.Setup(c => c.Sections).ReturnsEntitySet(new StoreHiveSection[] { });

            var sections = await service.GetHiveSectionsAsync();

            sections.Should().BeEmpty();
        }
Exemple #9
0
        public async Task GetHiveSections_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listSectionEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            context.Setup(c => c.Sections).ReturnsEntitySet(listSectionEntity);

            var hiveSections = await hiveSectionService.GetHiveSectionsAsync();

            Assert.Equal(13, hiveSections.Count);
        }
Exemple #10
0
        public async Task GetHiveSections_EmptySet_EmptyListReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            var result = await service.GetHiveSectionsAsync();

            Assert.Empty(result);
        }
Exemple #11
0
        public async Task GetHiveSectionsAsync_EmptyCollection_EmptyListReturned()
        {
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var service = new HiveSectionService(context.Object, new UserContext());

            var list = await service.GetHiveSectionsAsync();

            Assert.Empty(list);
        }
Exemple #12
0
        public async Task GetHiveSectionAsync_TenItemReturned([Frozen] Mock <IProductStoreHiveContext> context, HiveSectionService service, IFixture fixture)
        {
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var data = fixture.CreateMany <StoreHiveSection>(10).ToList();

            context.Setup(c => c.Sections).ReturnsEntitySet(data);

            var sections = await service.GetHiveSectionsAsync();

            sections.Count.Should().Be(data.Count);
        }
        public async Task GetHiveSections_EmptyCollectionTest()
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var service = new HiveSectionService(context.Object, userContext.Object);

            var sections = await service.GetHiveSectionsAsync();

            Assert.Empty(sections);
        }
        public async Task GetHiveSections_SetWhithFiveElements_FiveReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var sectionsArray = fixture.CreateMany <StoreHiveSection>(5).ToArray();

            context.Setup(x => x.Sections).ReturnsEntitySet(sectionsArray);
            var sections = await service.GetHiveSectionsAsync();

            sections.Should().HaveCount(sections.Count);
        }
Exemple #15
0
        public async Task GetHiveSectionsAsync_Create3FakeHiveSection_ExpectsGetting3HiveSections(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray();

            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);

            var hiveSections = await hiveSectionService.GetHiveSectionsAsync();

            Assert.Equal(3, hiveSections.Count);
        }
        public async Task GetHiveSectionsAsync_EmptyCollection_ReturnsEmptyCollection()
        {
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();

            mockHiveContext.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            mockHiveContext.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveSectionService(mockHiveContext.Object, mockUserContext.Object);

            var list = await service.GetHiveSectionsAsync();

            Assert.Empty(list);
        }
Exemple #17
0
        public async Task DeleteHiveSection_Successfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listEntity     = fixture.CreateMany <StoreHiveSection>(13).ToList();
            var listHiveEntity = new List <StoreHive>();

            context.Setup(x => x.Hives).ReturnsEntitySet(listHiveEntity);
            context.Setup(x => x.Sections).ReturnsEntitySet(listEntity);
            await hiveSectionService.SetStatusAsync(listEntity[0].Id, true);

            await hiveSectionService.DeleteHiveSectionAsync(listEntity[0].Id);

            var hiveSections = await hiveSectionService.GetHiveSectionsAsync();

            Assert.Equal(12, hiveSections.Count);
        }
        public async Task GetHiveSectionsAsync_SetWithFiveElements_HiveIdAsParametr_ReturnedElementsList()
        {
            var hiveId        = 2;
            var expectedCount = _sections.Where(s => s.StoreHiveId == hiveId).ToList().Count;

            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives);
            storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections);

            var service  = new HiveSectionService(storeContext.Object, userContext.Object);
            var sections = await service.GetHiveSectionsAsync(hiveId);

            Assert.Equal(expectedCount, sections.Count);
        }
        public async Task CreateHiveSectio_SetOneElement_OneReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var hives = fixture.CreateMany <StoreHive>(3).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(hives);
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var section = fixture.Create <UpdateHiveSectionRequest>();
            await service.CreateHiveSectionAsync(section, hives[0].Id);

            var result = await service.GetHiveSectionsAsync();

            result.Count.Should().Be(1);
        }
Exemple #20
0
        public async Task GetHiveSections_SetWithTenElements_ListWithTenElementsReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            fixture.Customize <StoreHiveSection>(c => c.Without(x => x.StoreHive)
                                                 .Without(x => x.Items)
                                                 .Without(x => x.Categories));
            var input = fixture.CreateMany <StoreHiveSection>(10).ToArray();

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(input);

            var result = await service.GetHiveSectionsAsync();

            Assert.True(input.Length == result.Count);
        }
Exemple #21
0
        public async void GetHiveSectionsNotEmpty()
        {
            var productContext = new Mock <IProductStoreHiveContext>();

            productContext.Setup(p => p.Hives).ReturnsEntitySet(new List <StoreHive>());

            var userContext = new Mock <IUserContext>();

            userContext.Setup(u => u.UserId).Returns(1);

            var service = new HiveSectionService(productContext.Object, userContext.Object);

            var sections = await service.GetHiveSectionsAsync();

            Assert.Empty(sections);
        }
        public async Task GetHiveSectionsAsync_SetWithFiveElements_ReturnedFiveElementsList()
        {
            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(_hives);
            storeContext.Setup(c => c.Sections).ReturnsAsyncEntitySet(_sections);

            var service  = new HiveSectionService(storeContext.Object, userContext.Object);
            var sections = await service.GetHiveSectionsAsync();

            Assert.Equal(_sections.Length, sections.Count);
            Assert.Equal(_sections[0].Code, sections[0].Code);
            Assert.Equal(_sections[2].Code, sections[2].Code);
            Assert.Equal(_sections[4].Code, sections[4].Code);
        }
        public async Task GetHiveSections_ByHiveId_SetFiveElement_OneReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var colections = fixture.CreateMany <StoreHiveSection>(5).ToArray();
            var hives      = new List <StoreHive> {
                new StoreHive {
                    Id = colections[0].StoreHiveId
                }
            };

            context.Setup(x => x.Hives).ReturnsEntitySet(hives);
            context.Setup(x => x.Sections).ReturnsEntitySet(colections);
            var section = await service.GetHiveSectionsAsync(colections[0].StoreHiveId);

            section[0].Id.Should().Be(colections[0].Id);
        }
        public async Task DeleteHiveSection_SetFiveElement_DeleteOne_FourReturned(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveSectionService service,
            IFixture fixture)
        {
            var hiveSections = fixture.CreateMany <StoreHiveSection>(5).ToList();
            var hives        = fixture.CreateMany <StoreHive>(3).ToArray();

            contex.Setup(x => x.Hives).ReturnsEntitySet(hives);
            contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSections);
            await service.SetStatusAsync(hiveSections[0].Id, true);

            await service.DeleteHiveSectionAsync(hiveSections[0].Id);

            var result = await service.GetHiveSectionsAsync();

            result.Count.Should().Be(4);
        }
        public async Task DeleteHiveSectionAsync_SuccessfulTest(int id)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, IsDeleted = true
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);

            await service.DeleteHiveSectionAsync(id);

            var sections = await service.GetHiveSectionsAsync();

            Assert.Empty(sections);
        }
Exemple #26
0
        public async Task GetHiveSections_SetWithTenHiveSectionsAndHiveId_ListWithFilteredHiveSectionsReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var firstHive = new StoreHive
            {
                Id = 1
            };
            string firstHiveName = "FirstHive";

            fixture.Customize <StoreHiveSection>(c => c.Without(x => x.StoreHive)
                                                 .Without(x => x.Items)
                                                 .Without(x => x.Categories)
                                                 .With(x => x.Name, firstHiveName)
                                                 .With(x => x.StoreHiveId, firstHive.Id)
                                                 .With(x => x.StoreHive, firstHive));
            var chainedToFirstHive = fixture.CreateMany <StoreHiveSection>(5).ToArray();

            var secondHive = new StoreHive
            {
                Id = 2
            };
            string secondHiveName = "SecondHive";

            fixture.Customize <StoreHiveSection>(c => c.Without(x => x.StoreHive)
                                                 .Without(x => x.Items)
                                                 .Without(x => x.Categories)
                                                 .With(x => x.Name, secondHiveName)
                                                 .With(x => x.StoreHiveId, secondHive.Id)
                                                 .With(x => x.StoreHive, secondHive));
            var chainedToSecondHive = fixture.CreateMany <StoreHiveSection>(5).ToArray();

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(chainedToFirstHive.Concat(chainedToSecondHive).ToArray());

            var result = await service.GetHiveSectionsAsync(firstHive.Id);

            Assert.True(chainedToSecondHive.Length == result.Count);
            Assert.All(result, h => h.Name.Equals(secondHiveName));
        }
Exemple #27
0
        public async void CreateHiveSectionSuccesFull()
        {
            var productContext = new Mock <IProductStoreHiveContext>();

            productContext.Setup(p => p.Hives).ReturnsEntitySet(new List <StoreHive>());

            var userContext = new Mock <IUserContext>();

            userContext.Setup(u => u.UserId).Returns(1);

            var service = new HiveSectionService(productContext.Object, userContext.Object);

            var createRequest = new UpdateHiveSectionRequest()
            {
                Name = "newHive",
                Id   = 1,
                Code = "111341"
            };
            await service.CreateHiveSectionAsync(createRequest);

            Assert.NotNull(service.GetHiveSectionsAsync());
        }
        public async Task GetHiveSectionsWithHiveId_SetWithTwoElements_TwoReturnedTest(int hiveId)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, StoreHiveId = 1
                },
                new StoreHiveSection()
                {
                    Id = 2, StoreHiveId = 1
                }
            });
            var service = new HiveSectionService(context.Object, userContext.Object);

            var sections = await service.GetHiveSectionsAsync(hiveId);

            Assert.Equal(2, sections.Count);
        }