Ejemplo n.º 1
0
        public async Task CreateHiveAsync_UniqueCode_HiveWithSpecifiedCodeCreated()
        {
            const string newCode = "cc";
            var          newHive = new UpdateHiveRequest()
            {
                Code = newCode
            };
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHive()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            var hive = await service.CreateHiveAsync(newHive);

            Assert.Equal(newCode, hive.Code);
        }
Ejemplo n.º 2
0
        public async Task CreateHiveAsync_CodeAlreadyPresent_RequestedResourceHasConflictExceptionThrown()
        {
            var newHive = new UpdateHiveRequest()
            {
                Code = "aa"
            };
            var mockUserContext       = new Mock <IUserContext>();
            var mockHiveContext       = new Mock <IProductStoreHiveContext>();
            List <StoreHive> hiveList = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 1, Code = "aa"
                },
                new StoreHive()
                {
                    Id = 2, Code = "bb"
                }
            };

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

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.CreateHiveAsync(newHive));
        }
Ejemplo n.º 3
0
        public async Task CreateHiveAsync_CreateHiveWithExistingHiveCode_ExceptionThrown()
        {
            var hives = new List <StoreHive>()
            {
                new StoreHive()
                {
                    Id = 0, Code = "CODE1"
                },
                new StoreHive()
                {
                    Id = 1, Code = "CODE2"
                }
            };
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var service = new HiveService(context.Object, new UserContext());
            var request = new UpdateHiveRequest {
                Code = "CODE1"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() =>
            {
                await service.CreateHiveAsync(request);
            });
        }
Ejemplo n.º 4
0
        public async void CreateHiveSuccesFull()
        {
            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 dbHive = new StoreHive
            {
                Id   = 1,
                Code = "12314321"
            };

            var myProductMock =
                new ProductStoreContextMock(new FakeEntitySet <StoreHive>(new List <StoreHive> {
                dbHive
            }), null, null);

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

            var createRequest = new UpdateHiveRequest
            {
                Name    = "newHive",
                Address = "address",
                Code    = "111341"
            };
            await service.CreateHiveAsync(createRequest);

            //Assert.NotNull(service.GetHivesAsync());
        }
        public async void CreateHiveAsync_EntityWithExistedCode_CustomExceptionThrows([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveRequest = fixture.Create <UpdateHiveRequest>();

            updateHiveRequest.Code = _hive[0].Code;

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.CreateHiveAsync(updateHiveRequest));
        }
Ejemplo n.º 6
0
        public async Task CreateHiveAsync_EmptyCollection_NewHiveReturned([Frozen] Mock <IProductStoreHiveContext> context, UpdateHiveRequest request, HiveService service)
        {
            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());

            var hive = await service.CreateHiveAsync(request);

            Assert.Equal(request.Code, hive.Code);
            Assert.Equal(request.Name, hive.Name);
            Assert.Equal(request.Address, hive.Address);
        }
Ejemplo n.º 7
0
        public async Task CreateHiveTestAsync([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            IList <StoreHive> hives = fixture.CreateMany <StoreHive>(10).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var createRequest = fixture.Create <UpdateHiveRequest>();
            var newHive       = service.CreateHiveAsync(createRequest).Result;

            Assert.NotNull(newHive);
        }
        public async void CreateHiveAsync_ValidEntity_SuccessfullHiveAddition([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            Configure(context, fixture);
            var updateHiveRequest = fixture.Create <UpdateHiveRequest>();

            var result = await service.CreateHiveAsync(updateHiveRequest);

            result.Code.Should().Be(updateHiveRequest.Code);
            result.Name.Should().Be(updateHiveRequest.Name);
            result.Address.Should().Be(updateHiveRequest.Address);
        }
        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 CreateHive_RequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var collection = fixture.CreateMany <StoreHive>(5).ToArray();
            var hive       = new UpdateHiveRequest {
                Code = collection[0].Code
            };

            context.Setup(x => x.Hives).ReturnsEntitySet(collection);
            Func <Task> act = async() => await service.CreateHiveAsync(hive);

            act.Should().Throw <RequestedResourceHasConflictException>();
        }
Ejemplo n.º 11
0
        public async Task CreateHive_AddedSuccessfuly_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(x => x.Hives).ReturnsEntitySet(listEntity);
            context.Setup(x => x.Sections).ReturnsEntitySet(listSectionEntity);
            var createRequest = fixture.Create <UpdateHiveRequest>();
            var addedHive     = await hiveService.CreateHiveAsync(createRequest);

            var hive = await hiveService.GetHiveAsync(addedHive.Id);

            Assert.Equal(hive.Name, createRequest.Name);
            Assert.Equal(hive.Address, createRequest.Address);
            Assert.Equal(hive.Code, createRequest.Code);
        }
Ejemplo n.º 12
0
        public async Task CreateHiveAsync_EmptyCollection_NewHiveReturned()
        {
            var context = new Mock <IProductStoreHiveContext>();

            context.Setup(c => c.Hives).ReturnsEntitySet(new List <StoreHive>());
            var service = new HiveService(context.Object, new UserContext());
            var request = new UpdateHiveRequest {
                Code = "CODE1", Name = "Hive", Address = "Test"
            };

            var hive = await service.CreateHiveAsync(request);

            Assert.Equal(request.Code, hive.Code);
            Assert.Equal(request.Name, hive.Name);
            Assert.Equal(request.Address, hive.Address);
        }
Ejemplo n.º 13
0
        public async Task CreateHiveAsync_UpdateHiveRequest_RequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var dbUpdateHiveRequest = fixture.Create <UpdateHiveRequest>();

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

            dbHives[0].Code = dbUpdateHiveRequest.Code;

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

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(
                () => service.CreateHiveAsync(dbUpdateHiveRequest));
        }
Ejemplo n.º 14
0
        public async Task CreateHiveAsync_UpdateHiveRequest_Success(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service,
            IFixture fixture)
        {
            var dbHives = fixture.CreateMany <StoreHive>(0).ToList();

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

            var dbUpdateHiveRequest = fixture.Create <UpdateHiveRequest>();

            var createdHive = await service.CreateHiveAsync(dbUpdateHiveRequest);

            Assert.Equal(dbUpdateHiveRequest.Name, createdHive.Name);
            Assert.Equal(dbUpdateHiveRequest.Address, createdHive.Address);
            Assert.Equal(dbUpdateHiveRequest.Code, createdHive.Code);
        }
Ejemplo n.º 15
0
        public async Task CreateHiveAsync_CreateRequestAsParametr_ExistedCode_ThrowException()
        {
            var createReq = new UpdateHiveRequest()
            {
                Name    = "CreateName",
                Code    = _hives[0].Code,
                Address = "string"
            };

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

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

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

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.CreateHiveAsync(createReq));
        }
Ejemplo n.º 16
0
        public async Task CreateHiveAsync_PassesUpdateHiveRequest_ThrowsRequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            string code              = "12345";
            var    storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var    storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            storeHives[0].Code = code;
            var createRequest = new UpdateHiveRequest {
                Address = "Kuprevicha 1-1", Code = code, Name = "qwerty"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(
                () => hiveService.CreateHiveAsync(createRequest));
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        public async Task CreateHiveAsync_CreateRequestAsParametr_ReturnedCreatedElement()
        {
            var createReq = new UpdateHiveRequest()
            {
                Name    = "CreateName",
                Code    = "TEST1",
                Address = "string"
            };

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

            storeContext.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            var service = new HiveService(storeContext.Object, userContext.Object);
            var hive    = await service.CreateHiveAsync(createReq);

            Assert.Equal(createReq.Name, hive.Name);
            Assert.Equal(createReq.Code, hive.Code);
            Assert.Equal(createReq.Address, hive.Address);
        }
Ejemplo n.º 19
0
        public async Task CreateHive_TryCreateHive_HiveEntityReturned(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new UpdateHiveRequest
            {
                Code    = "Code",
                Name    = "Name",
                Address = "Address"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            var createdHive = await service.CreateHiveAsync(hive);

            Assert.True(
                createdHive.Name == hive.Name &&
                createdHive.Code == hive.Code &&
                createdHive.Address == hive.Address &&
                createdHive.IsDeleted == false);
        }
Ejemplo n.º 20
0
        public async Task CreateHive_TryCreateHive_ElementWasAddedToContext(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new UpdateHiveRequest
            {
                Code    = "Code",
                Name    = "Name",
                Address = "Address"
            };

            context.Setup(c => c.Hives).ReturnsAsyncEntitySet(new StoreHive[0]);

            await service.CreateHiveAsync(hive);

            Assert.True(context.Object.Hives.Count() == 1);
            Assert.Contains(context.Object.Hives, h => h.Code == hive.Code &&
                            h.Name == hive.Name &&
                            h.Address == hive.Address &&
                            h.IsDeleted == false);
        }
Ejemplo n.º 21
0
        public async Task CreateHiveAsync_PassesUpdateHiveRequest_ExpectsSuccessfullEqualityAssertion(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            var storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            var createRequest = new UpdateHiveRequest {
                Address = "Kuprevicha 1-1", Code = "12345", Name = "qwerty"
            };

            var expectedHive = await hiveService.CreateHiveAsync(createRequest);

            var actualHive = await hiveService.GetHiveAsync(expectedHive.Id);

            Assert.Equal(expectedHive.Id, actualHive.Id);
            Assert.Equal(expectedHive.Name, actualHive.Name);
            Assert.Equal(expectedHive.Address, actualHive.Address);
            Assert.Equal(expectedHive.Code, actualHive.Code);
            Assert.Equal(expectedHive.IsDeleted, actualHive.IsDeleted);
        }
Ejemplo n.º 22
0
        public async Task CreateHive_CreateHiveWithExistedCode_ExceptionThrown(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveService service)
        {
            var hive = new StoreHive
            {
                Id   = 1,
                Code = "Code"
            };

            var newHive = new UpdateHiveRequest
            {
                Code = hive.Code
            };

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

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.CreateHiveAsync(newHive));
        }
Ejemplo n.º 23
0
        public void CreateHiveAsync_SuchHiveAlreadyExistsTest(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>()
            {
                new StoreHive()
                {
                    Code = "11111"
                }
            });
            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
            };

            Assert.ThrowsAsync <RequestedResourceHasConflictException>(async() => await service.CreateHiveAsync(request));
        }
Ejemplo n.º 24
0
        public async Task CreateHive_ConflictException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService)
        {
            var listEntity    = fixture.CreateMany <StoreHive>(13).ToList();
            var createRequest = fixture.Create <UpdateHiveRequest>();

            createRequest.Code = listEntity[0].Code;
            context.Setup(x => x.Hives).ReturnsEntitySet(listEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => hiveService.CreateHiveAsync(createRequest));

            Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType());
        }