Exemple #1
0
        public async Task GetHivesAsync_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 HiveService(mockHiveContext.Object, mockUserContext.Object);

            var list = await service.GetHivesAsync();

            Assert.Equal(2, list.Count);
        }
Exemple #2
0
        public async Task GetHivesAsync_CollectionWithThreeElements_ThreeElementsListReturned()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0
                },
                new StoreHive()
                {
                    Id = 1
                },
                new StoreHive()
                {
                    Id = 2
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

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

            var list = await service.GetHivesAsync();

            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);
        }
Exemple #3
0
        public async Task GetHivesTestAsync_UsingDataDouble()
        {
            var data = new List <StoreHive>
            {
                new StoreHive {
                    Name = "Hive1"
                },
                new StoreHive {
                    Name = "Hive2"
                },
                new StoreHive {
                    Name = "Hive3"
                },
            }.AsQueryable();

            var mockSet = new Mock <IEntitySet <StoreHive> >();

            mockSet.As <IQueryable <StoreHive> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <StoreHive> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <StoreHive> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <StoreHive> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <IProductStoreHiveContext>();

            mockContext.Setup(c => c.Hives).Returns(mockSet.Object);

            Mock <IUserContext> userContext = new Mock <IUserContext>();
            var service = new HiveService(mockContext.Object, userContext.Object);
            var hives   = await service.GetHivesAsync();

            Assert.Equal(3, hives.Count());
            Assert.Equal("Hive1", hives[0].Name);
            Assert.Equal("Hive2", hives[1].Name);
            Assert.Equal("Hive3", hives[2].Name);
        }
Exemple #4
0
        public async Task GetHives_HiveAndChainedSection_HiveListItemWithProperlyCountedSections(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id = 1
            };

            var hiveSection = new StoreHiveSection
            {
                Id          = 1,
                StoreHive   = hive,
                StoreHiveId = 1
            };

            hive.Sections = new[] { hiveSection };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new[] { hive });
            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { hiveSection });

            var result = await service.GetHivesAsync();

            Assert.True(result[0].HiveSectionCount == 1);
        }
Exemple #5
0
        public async Task GetHivesAsync_WithoutParameters_HiveListItems(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            // arrange

            var dbHives = fixture.CreateMany <StoreHive>(2).ToList();

            var dbSections = fixture.CreateMany <StoreHiveSection>(5).ToList();

            dbSections[0].StoreHiveId = dbHives[0].Id;
            dbSections[1].StoreHiveId = dbHives[0].Id;
            dbSections[2].StoreHiveId = dbHives[1].Id;
            dbSections[3].StoreHiveId = dbHives[1].Id;
            dbSections[4].StoreHiveId = dbHives[1].Id;

            context.Setup(s => s.Hives).ReturnsEntitySet(dbHives);

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

            // act

            var hiveListItems = await service.GetHivesAsync();

            // assert

            Assert.Equal(2, hiveListItems.Count);

            Assert.Collection(
                hiveListItems,
                item => Assert.Equal(2, item.HiveSectionCount),
                item => Assert.Equal(3, item.HiveSectionCount));
        }
        public async Task GetHiveAsync_EmptyListReturned([Frozen] Mock <IProductStoreHiveContext> context, HiveService service)
        {
            context.Setup(c => c.Hives).ReturnsEntitySet(new StoreHive[] { });

            var hives = await service.GetHivesAsync();

            hives.Should().BeEmpty();
        }
Exemple #7
0
        public async Task GetHivesTestAsync([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            IList <StoreHive> hives = fixture.CreateMany <StoreHive>(10).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var amount = await service.GetHivesAsync();

            amount.Should().HaveSameCount(hives);
        }
Exemple #8
0
        public async Task GetHives_EmptySet_EmptyListReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            var result = await service.GetHivesAsync();

            Assert.Empty(result);
        }
        public async void GetHivesAsync_TenEntities_SeccessfulResult([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var sections = fixture.CreateMany <StoreHiveSection>(10).ToList();

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

            var result = await service.GetHivesAsync();

            result.Should().HaveCount(_hive.Count);
        }
        public async Task GetHives_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity        = fixture.CreateMany <StoreHive>(13).ToList();
            var listSectionEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

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

            var hives = await hiveService.GetHivesAsync();

            Assert.Equal(13, hives.Count);
        }
        public async Task GetHiveAsync_TenItemReturned([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var data = fixture.CreateMany <StoreHive>(10).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(data);
            context.Setup(s => s.Sections).ReturnsEntitySet(new List <StoreHiveSection>());

            var hives = await service.GetHivesAsync();

            hives.Count.Should().Be(data.Count);
        }
Exemple #12
0
        public async Task GetHivesAsync_EmptyCollection_EmptyListReturned()
        {
            var context = new Mock <IProductStoreHiveContext>();

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

            var list = await service.GetHivesAsync();

            Assert.Empty(list);
        }
        public async Task GetHivesAsync_EmptyCollectionTest()
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, userContext.Object);

            var hives = await service.GetHivesAsync();

            Assert.Empty(hives);
        }
        public async Task GetHives_SetFiveElement_FiveElementReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var colection = fixture.CreateMany <StoreHive>(5).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(colection);
            context.Setup(x => x.Sections).ReturnsEntitySet(colection[0].Sections.ToList());
            var hives = await service.GetHivesAsync();

            hives.Count.Should().Be(colection.Length);
        }
        public async Task CreateHive_SetOne_ReturnedOne(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            context.Setup(x => x.Hives).ReturnsEntitySet(new List <StoreHive>());
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var hive = fixture.Create <UpdateHiveRequest>();
            await service.CreateHiveAsync(hive);

            var hives = await service.GetHivesAsync();

            hives.Count.Should().Be(1);
        }
        public async Task DeleteHive_Successfuly_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity = fixture.CreateMany <StoreHive>(13).ToList();

            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            context.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            await hiveService.SetStatusAsync(listEntity[0].Id, true);

            await hiveService.DeleteHiveAsync(listEntity[0].Id);

            var hives = await hiveService.GetHivesAsync();

            Assert.Equal(12, hives.Count);
        }
Exemple #17
0
        public async Task GetHivesAsync_Create3FakeHives_ExpectsGetting3Hives(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToArray();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray();

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

            var hives = await hiveService.GetHivesAsync();

            Assert.Equal(3, hives.Count);
        }
Exemple #18
0
        public async Task GetHives_SetWithTenElements_ListWithTenElementsReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            fixture.Customize <StoreHive>(c => c.Without(x => x.Sections));
            var input = fixture.CreateMany <StoreHive>(10).ToArray();

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(input);
            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            var result = await service.GetHivesAsync();

            Assert.True(input.Length == result.Count);
        }
Exemple #19
0
        public async Task DeleteHiveAsync_HiveWithTrueStatus_HiveDeleted([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var hives = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].IsDeleted = true;
            context.Setup(c => c.Hives).ReturnsEntitySet(hives);

            await service.DeleteHiveAsync(hives[0].Id);

            var list = await service.GetHivesAsync();

            list.Should().BeEmpty();
        }
        public async void GetHivesAsyncReturnsEmpty()
        {
            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 HiveService(productContext.Object, userContext.Object);

            var hives = await service.GetHivesAsync();

            Assert.Empty(hives);
        }
Exemple #21
0
        public async Task GetHivesAsync_SetWithFiveElements_ReturnedFiveElementsList()
        {
            var storeContext = new Mock <IProductStoreHiveContext>();
            var userContext  = new Mock <IUserContext>();

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

            var service = new HiveService(storeContext.Object, userContext.Object);
            var hives   = await service.GetHivesAsync();

            Assert.Equal(_hives.Length, hives.Count);
            Assert.Equal(_hives[0].Code, hives[0].Code);
            Assert.Equal(_hives[2].Code, hives[2].Code);
            Assert.Equal(_hives[4].Code, hives[4].Code);
        }
Exemple #22
0
        public async Task GetHivesAsync_CollectionWithThreeElements_ThreeElementsListReturned([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var hives = fixture.CreateMany <StoreHive>(3).ToArray();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());

            var list = await service.GetHivesAsync();

            list.Should().HaveCount(3);
            list.Should().Contain(h => h.Id == hives[0].Id);
            list.Should().Contain(h => h.Id == hives[1].Id);
            list.Should().Contain(h => h.Id == hives[2].Id);
        }
        public async Task DeleteHive_SetFiveElement_DeleteOne_FourReturned(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToList();

            contex.Setup(x => x.Hives).ReturnsEntitySet(collection);
            contex.Setup(x => x.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            await service.SetStatusAsync(collection[0].Id, true);

            await service.DeleteHiveAsync(collection[0].Id);

            var result = await service.GetHivesAsync();

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

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

            await service.DeleteHiveAsync(id);

            var hives = await service.GetHivesAsync();

            Assert.Empty(hives);
        }
        public async Task CreateHiveAsync_SuccessfulTest(string name, string code, string address)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            context.Setup(c => c.Sections).ReturnsEntitySet(new List <StoreHiveSection>());
            var service = new HiveService(context.Object, userContext.Object);
            var request = new UpdateHiveRequest
            {
                Name    = name,
                Code    = code,
                Address = address
            };

            await service.CreateHiveAsync(request);

            var hives = await service.GetHivesAsync();

            Assert.Single(hives);
        }
        public async Task GetHivesAsync_SetWithTwoElements_TwoReturnedTest()
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

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

            var hives = await service.GetHivesAsync();

            Assert.Equal(2, hives.Count);
        }
Exemple #27
0
        public async Task DeleteHiveAsync_IdPresent_RequestedHiveDeleted()
        {
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, IsDeleted = true
                },
                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 HiveService(mockHiveContext.Object, mockUserContext.Object);

            await service.DeleteHiveAsync(1);

            var hives = await service.GetHivesAsync();

            Assert.DoesNotContain(hives, h => h.Id == 1);
        }