public async Task SetStatusAsync_IdPresent_RequestedHiveStatusChanged()
        {
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHiveSection()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            await service.SetStatusAsync(1, false);

            var hive = await service.GetHiveSectionAsync(1);

            Assert.False(hive.IsDeleted);
        }
        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 UpdateHiveSectionAsync_ValidRequest_HiveUpdated()
        {
            var newHiveSection = new UpdateHiveSectionRequest()
            {
                Code = "cc"
            };
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHiveSection()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            var updatedHiveSection = await service.UpdateHiveSectionAsync(1, newHiveSection);

            Assert.Equal(newHiveSection.Code, updatedHiveSection.Code);
        }
        public async Task UpdateHiveSectionAsync_IdNotPresent_RequestedResourceNotFoundExceptionThrown()
        {
            var newHiveSection = new UpdateHiveSectionRequest()
            {
                Code = "aa"
            };
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHiveSection()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.UpdateHiveSectionAsync(3, newHiveSection));
        }
        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 UpdateHiveSectionAsync_SuccessfulTest(int id, string name, string code)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

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

            await service.UpdateHiveSectionAsync(id, request);

            var actualHive = await service.GetHiveSectionAsync(id);

            Assert.Equal(code, actualHive.Code);
        }
        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);
        }
Esempio n. 8
0
        public async Task UpdateHiveSection_UpdateHiveSectionWithExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var existedHiveSection = new StoreHiveSection
            {
                Id   = 1,
                Code = "Code"
            };

            var updatedExistedHiveSection = new StoreHiveSection
            {
                Id   = 2,
                Code = "Code1"
            };

            var newHiveSection = new UpdateHiveSectionRequest
            {
                Code = "Code"
            };

            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new[] { existedHiveSection, updatedExistedHiveSection });

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.UpdateHiveSectionAsync(updatedExistedHiveSection.Id, newHiveSection));
        }
Esempio n. 9
0
        public async Task UpdateHiveSectionAsync_ChangeSectionProperties_UpdatedSectionReturned()
        {
            var sections = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHiveSection()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(sections);
            var service = new HiveSectionService(context.Object, new UserContext());
            var request = new UpdateHiveSectionRequest {
                Code = "CODE3", Name = "New Name"
            };

            var section = await service.UpdateHiveSectionAsync(1, request);

            Assert.Equal(request.Code, section.Code);
            Assert.Equal(request.Name, section.Name);
        }
        public void UpdateHiveSectionAsync_NoHiveWithSuchIdTest(int id, string name, string code)
        {
            var context     = new Mock <IProductStoreHiveContext>();
            var userContext = new Mock <IUserContext>();

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

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.UpdateHiveSectionAsync(id, request));
        }
        public async Task CreateHiveSectionAsync_UniqueCode_HiveSectionWithSpecifiedCodeCreated()
        {
            const string newCode        = "cc";
            var          newHiveSection = new UpdateHiveSectionRequest()
            {
                Code = newCode
            };
            var mockUserContext = new Mock <IUserContext>();
            var mockHiveContext = new Mock <IProductStoreHiveContext>();
            List <StoreHiveSection> hiveSectionsList = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHiveSection()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            var hive = await service.CreateHiveSectionAsync(1, newHiveSection);

            Assert.Equal(newCode, hive.Code);
        }
        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);
        }
Esempio n. 13
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));
        }
Esempio n. 15
0
        public async Task UpdateHiveSectionAsync_ChangeCodeToExistingSectionCode_ExceptionThrown()
        {
            var sections = new List <StoreHiveSection>()
            {
                new StoreHiveSection()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHiveSection()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Sections).ReturnsEntitySet(sections);
            var service = new HiveSectionService(context.Object, new UserContext());
            var request = new UpdateHiveSectionRequest {
                Code = "CODE1"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() =>
            {
                await service.UpdateHiveSectionAsync(1, request);
            });
        }
Esempio n. 16
0
        public async Task DeleteHiveSection_DeletingHiveSectionWithUnexistedId_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            context.Setup(c => c.Sections).ReturnsAsyncEntitySet(new StoreHiveSection[0]);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveSectionAsync(1));
        }
        public async Task GetHiveSections_EmptySet_ZeroReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            context.Setup(x => x.Sections).ReturnsEntitySet(new StoreHiveSection[] { });
            var sections = await service.GetHiveSectionsAsync();

            sections.Should().BeEmpty();
        }
        public async Task SetStatusAsync_HiveSection_RequestedResourceNotFoundException(IFixture fixture)
        {
            var storeSectionHives = fixture.CreateMany <StoreHiveSection>(0).ToArray();

            _context.Setup(s => s.Sections).ReturnsEntitySet(storeSectionHives);

            var service = new HiveSectionService(_context.Object, _userContext.Object);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(1, true));
        }
Esempio n. 19
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);
        }
        public void DeleteHiveSectionAsync_NoSectionWithSuchIdTest(int id)
        {
            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);

            Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.DeleteHiveSectionAsync(id));
        }
Esempio n. 21
0
        public async Task SetStatusAsync_PassesHiveSectionIdAndDeleteStatus_ExpectsRequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToArray();

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveSectionService.SetStatusAsync(123, false));
        }
Esempio n. 22
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);
        }
        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);
        }
        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 SetStatus_RequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var section = fixture.Create <StoreHiveSection>();

            context.Setup(x => x.Sections).ReturnsEntitySet(new StoreHiveSection[] { section });
            Func <Task> act = async() => await service.SetStatusAsync(0, true);

            act.Should().Throw <RequestedResourceNotFoundException>();
        }
Esempio n. 26
0
        public async Task SetStatusAsync_UpdateNonExistentSection_ExceptionThrown()
        {
            var context = new Mock <IProductStoreHiveContext>();

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() =>
            {
                await service.SetStatusAsync(1, true);
            });
        }
Esempio n. 27
0
        public async Task GetHiveSectionAsync_EmptyCollection_ExceptionThrown()
        {
            var context = new Mock <IProductStoreHiveContext>();

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() =>
            {
                await service.GetHiveSectionAsync(0);
            });
        }
        public async Task GetHiveSection_AnyElementSet_OneReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var section = fixture.Create <StoreHiveSection>();

            context.Setup(x => x.Sections).ReturnsEntitySet(new StoreHiveSection[] { section });
            var sectionResult = await service.GetHiveSectionAsync(section.Id);

            sectionResult.Id.Should().Be(section.Id);
        }
Esempio n. 29
0
        public async Task GetHiveSectionAsync_PassesHiveSectionId_ThrowsRequestedResourceNotFoundException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveSectionService hiveSectionService,
            IFixture fixture,
            int hiveSectionId)
        {
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(0).ToArray();

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(
                () => hiveSectionService.GetHiveSectionAsync(hiveSectionId));
        }
Esempio n. 30
0
        public async Task GetHiveSection_RequestWithUnExistedId_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service)
        {
            var hiveSection = new StoreHiveSection
            {
                Id = 1
            };

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

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(async() => await service.GetHiveSectionAsync(2));
        }