Exemplo n.º 1
0
 private void ConfigureData()
 {
     gateway = new Domain.Gateway()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1"
     };
     gatewayDto = new GatewayDto()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1"
     };
     gatewayDetailsDto = new GatewayDetailsDto()
     {
         Id           = 1,
         SerialNumber = "G1",
         IPV4Address  = "12.12.1.2",
         Name         = "G1",
         Devices      = new List <DeviceDto>()
     };
     mapper = new MapperConfiguration(c => c.AddProfile <AutoMapping>()).CreateMapper();
     gatewayRepositoryMock.Get(gateway.Id).Returns(Task <Domain.Gateway> .FromResult(gateway));
     gatewayRepositoryMock.Insert(gateway).Returns(Task <Domain.Gateway> .FromResult(gateway));
     gatewayRepositoryMock.Delete(gateway).Returns(Task <Domain.Gateway> .FromResult(gateway));
     service = new GatewayService(this.gatewayRepositoryMock, mapper);
 }
Exemplo n.º 2
0
        public async void Delete_Gateway_Deletes_Element()
        {
            builder.UseInMemoryDatabase("Delete_Gateway_Deletes_Element");
            var options = builder.Options;
            var gateway = new Domain.Gateway();

            using (var context = new TestDbContext(options))
            {
                gateway = new Domain.Gateway()
                {
                    Id           = 1,
                    SerialNumber = "G1",
                    IPV4Address  = "12.12.1.2",
                    Name         = "G1"
                };
                context.Add(gateway);
                context.SaveChanges();
            }

            using (var context = new TestDbContext(options))
            {
                var repository = new GatewayRepository(context);
                await repository.Delete(gateway);

                gateway = context.Gateways.Find(1);
            }

            Assert.Null(gateway);
        }
Exemplo n.º 3
0
        public async void Insert_Null_Gateway_Throws_Error()
        {
            builder.UseInMemoryDatabase("Insert_Null_Gateway_Throws_Error");
            var options = builder.Options;

            Domain.Gateway gateway = new Domain.Gateway();
            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                var repository = new GatewayRepository(context);

                await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.Insert(null));
            }
        }
Exemplo n.º 4
0
        public async void Delete_Non_Existing_Gateway_In_Empty_DB_Throws_Error()
        {
            builder.UseInMemoryDatabase("Delete_Non_Existing_Gateway_In_Empty_DB_Throws_Error");
            var options = builder.Options;

            Domain.Gateway gateway = new Domain.Gateway();
            using (var context = new TestDbContext(options))
            {
                var repository = new GatewayRepository(context);
                gateway = new Domain.Gateway()
                {
                    Id           = 1,
                    SerialNumber = "G1",
                    IPV4Address  = "12.12.1.2",
                    Name         = "G1"
                };
                await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() => await repository.Delete(gateway));
            }
        }
Exemplo n.º 5
0
        public async void Delete_Null_Gateway_Throws_Error()
        {
            builder.UseInMemoryDatabase("Delete_Null_Gateway_Throws_Error");
            var options = builder.Options;

            Domain.Gateway gateway = new Domain.Gateway();
            using (var context = new TestDbContext(options))
            {
                var repository = new GatewayRepository(context);
                gateway = new Domain.Gateway()
                {
                    Id           = 1,
                    SerialNumber = "G1",
                    IPV4Address  = "12.12.1.2",
                    Name         = "G1"
                };
                context.Gateways.Add(gateway);
                context.SaveChanges();
                await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.Delete(null));
            }
        }
Exemplo n.º 6
0
        public async void Get_Gateway_Returns_Element_If_Exists()
        {
            builder.UseInMemoryDatabase("Get_Gateway_Returns_Element_If_Exists");
            var options = builder.Options;
            var gateway = new Domain.Gateway()
            {
                Id           = 1,
                SerialNumber = "G1",
                IPV4Address  = "12.12.1.2",
                Name         = "G1"
            };

            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                context.Add(gateway);
                context.SaveChanges();
            }

            Domain.Gateway existingGateway    = null;
            Domain.Gateway nonExistingGateway = null;

            using (var context = new TestDbContext(options))
            {
                var repository = new GatewayRepository(context);
                existingGateway = await repository.Get(1);

                nonExistingGateway = await repository.Get(2);
            }

            Assert.True(existingGateway != null && nonExistingGateway == null);
            Assert.True(existingGateway.Id == gateway.Id &&
                        existingGateway.IPV4Address == gateway.IPV4Address &&
                        existingGateway.Name == gateway.Name &&
                        existingGateway.SerialNumber == gateway.SerialNumber);
        }
Exemplo n.º 7
0
        public async void Insert_Gateway_Inserts_Element()
        {
            builder.UseInMemoryDatabase("Insert_Gateway_Inserts_Element");
            var options = builder.Options;

            Domain.Gateway gateway = new Domain.Gateway();
            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                var repository = new GatewayRepository(context);
                await repository.Insert(new Domain.Gateway()
                {
                    Id           = 1,
                    SerialNumber = "G1",
                    IPV4Address  = "12.12.1.2",
                    Name         = "G1"
                });

                gateway = context.Gateways.Find(1);
            }

            Assert.True(gateway != null && gateway.Id == 1);
        }