Exemplo n.º 1
0
        public void Deve_Realizar_Post(string address, Environment environment)
        {
            FakeContext fakeContext = CreateAndFillContextWithSource();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var newSource = new SourceCreateDTO {
                    Address = address, Environment = environment
                };

                Assert.IsNotNull(newSource);

                Assert.IsNull(service.Get().Where(x => x.Environment == newSource.Environment.ToString() && x.Address == newSource.Address).FirstOrDefault());

                var savedSource = service.Create(newSource);

                if (savedSource.Success == false)
                {
                    Assert.AreEqual(false, savedSource.Success);
                    Assert.AreEqual("Fail", savedSource.Message);
                    Assert.IsNull(savedSource.Data);
                }
                else
                {
                    Assert.AreEqual(true, savedSource.Success);
                    Assert.AreEqual("Succesfully registred the source.", savedSource.Message);
                    Assert.IsNotNull(savedSource.Data);
                }
            }
        }
Exemplo n.º 2
0
        public void Deve_Obter_Todos_Os_Errors()
        {
            var fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);
                var actual  = service.Get().ToList();

                Assert.IsNotNull(actual);
                var expectedNumbers = context.Errors.Count();
                Assert.AreEqual(expectedNumbers, actual.ToList().Count());

                for (var i = 0; i < actual.ToList().Count(); i++)
                {
                    Assert.IsNotNull(actual[i].Id);
                    Assert.IsNotNull(actual[i].UserId);
                    Assert.IsNotNull(actual[i].FullName);
                    Assert.IsNotNull(actual[i].Title);
                    Assert.IsNotNull(actual[i].Details);
                    Assert.IsNotNull(actual[i].CreatedAt);
                    Assert.IsNotNull(actual[i].Level);
                    Assert.IsNotNull(actual[i].Environment);
                    Assert.IsNotNull(actual[i].Address);
                    Assert.IsNotNull(actual[i].Archived);
                    Assert.AreEqual(actual[i].Id, (1 + i));
                }
            }
        }
Exemplo n.º 3
0
 public SourceRepository(
     CentralDeErrorContext context,
     IMapper mapper
     )
 {
     _mapper  = mapper;
     _context = context;
 }
 public ErrorRepository(
     CentralDeErrorContext context,
     IMapper mapper
     )
 {
     _context = context;
     _mapper  = mapper;
 }
Exemplo n.º 5
0
        public void Parametro_Vazio_deve_retornar_Exception_ao_tentar_realizar_Post()
        {
            var fakeContext = new FakeContext("SourceRepositoryTests");

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);
                service.Create(null);
            }
        }
Exemplo n.º 6
0
        public void Parametro_Vazio_deve_retornar_Exception_ao_tentar_realizar_Post()
        {
            var fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                service.Create(null, null);
            }
        }
Exemplo n.º 7
0
        public void Deve_Obter_O_Source_De_Id_Correto(int id)
        {
            FakeContext fakeContext = CreateAndFillContextWithSource();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var atual = service.Get(id);
                Assert.IsNotNull(atual);

                Assert.AreEqual(id, atual.Id);
            }
        }
Exemplo n.º 8
0
 public void FillWithAllSource()
 {
     using (var context = new CentralDeErrorContext(FakeOptions))
     {
         if (context.Sources.Count() == 0)
         {
             foreach (var item in Get <SourceCreateDTO>())
             {
                 var source = Source.Create(item.Id, item.Address, item.Environment);
                 context.Add(source);
                 context.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 9
0
 public void FillWithAllUsers()
 {
     using (var context = new CentralDeErrorContext(FakeOptions))
     {
         if (context.Users.Count() == 0)
         {
             foreach (var item in Get <RegisterCreateDTO>())
             {
                 var user = User.Create(item.FullName, item.Email, item.Email);
                 context.Add(user);
                 context.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 10
0
        public void Deve_Falhar_Ao_Tentar_Deletar_Source_Inexistente(int id)
        {
            FakeContext fakeContext = CreateAndFillContextWithSource();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var result = service.Delete(id);

                var resultFail = new ResultDTO(false, $"Source id: {id} not found.", null);

                Assert.AreEqual(new { resultFail.Success, resultFail.Message, resultFail.Data },
                                new { result.Success, result.Message, result.Data });
            }
        }
Exemplo n.º 11
0
        public void Deve_Realizar_Error_Archive(int id)
        {
            FakeContext fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var result = service.Archive(id);

                var resultNotFail = new ResultDTO(true, "Successfuly archived", result.Data);
                Assert.AreEqual(new { resultNotFail.Success, resultNotFail.Message },
                                new { result.Success, result.Message });
                Assert.IsNotNull(result.Data);
            }
        }
Exemplo n.º 12
0
        public void Deve_Falhar_Ao_Realizar_Error_Unarchive_Com_Id_inexistente(int id)
        {
            FakeContext fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var result = service.Unarchive(id);

                var resultFail = new ResultDTO(false, $"Error id: {id} not found.", null);

                Assert.IsNull(result.Data);
                Assert.AreEqual(new { resultFail.Success, resultFail.Message },
                                new { result.Success, result.Message });
            }
        }
Exemplo n.º 13
0
        public void Deve_Falhar_Ao_Postar_Source_Com_Endereco_E_Ambiente_Ja_Existente(string address, Environment environment)
        {
            FakeContext fakeContext = CreateAndFillContextWithSource();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var newSource = new SourceCreateDTO {
                    Address = address, Environment = environment
                };

                var result = service.Create(newSource);

                Assert.AreEqual(false, result.Success);
                Assert.AreEqual("Source already existis.", result.Message);
                Assert.AreEqual(null, result.Data);
            }
        }
Exemplo n.º 14
0
 public void FillWithAllErrors()
 {
     FillWithAllSource();
     FillWithAllUsers();
     using (var context = new CentralDeErrorContext(FakeOptions))
     {
         if (context.Errors.Count() == 0)
         {
             foreach (var item in Get <ErrorCreateDTO>())
             {
                 var user = context.Users.FirstOrDefault();
                 item.AddUserId(user.Id);
                 var error = Error.Create(item.Id, item.UserId, item.Title, item.Details, item.Level, item.SourceId);
                 context.Add(error);
                 context.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 15
0
        public void Deve_Obter_Todos_Os_Sources()
        {
            FakeContext fakeContext = CreateAndFillContextWithSource();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var atual = service.Get().ToList();

                Assert.IsNotNull(atual);

                for (var i = 0; i < atual.ToList().Count(); i++)
                {
                    Assert.IsNotNull(atual[i].Id);
                    Assert.IsNotNull(atual[i].Address);
                    Assert.IsNotNull(atual[i].Environment);
                    Assert.AreEqual(atual[i].Id, (1 + i));
                }
            }
        }
Exemplo n.º 16
0
        public void Deve_Falhar_Ao_Postar_Error_Com_Source_Invalido(string title, string details, int sourceId, Level level)
        {
            FakeContext fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var newSource = new ErrorCreateDTO {
                    Title = title, Details = details, SourceId = sourceId, Level = level
                };
                var service = CreateService(fakeContext, context);

                Assert.IsNotNull(newSource);
                var user = context.Users.FirstOrDefault();

                var identity = new[] { new Claim("Name", user.Id) };
                var result   = service.Create(newSource, new ClaimsPrincipal(new ClaimsIdentity(identity)));

                Assert.AreEqual(false, result.Success);
                Assert.AreEqual("Invalid Source Id.", result.Message);
                Assert.AreEqual(null, result.Data);
            }
        }
Exemplo n.º 17
0
        public void Deve_Realizar_Post(string title, string details, int sourceId, Level level)
        {
            FakeContext fakeContext = CreateAndFillContextWithError();

            using (var context = new CentralDeErrorContext(fakeContext.FakeOptions))
            {
                var service = CreateService(fakeContext, context);

                var newError = new ErrorCreateDTO {
                    Title = title, Details = details, SourceId = sourceId, Level = level
                };

                Assert.IsNotNull(newError);

                Assert.IsNull(service.Get().Where(x => x.Id == newError.Id).FirstOrDefault());

                var user = context.Users.FirstOrDefault();

                var identity = new[] { new Claim("id", user.Id) };

                var savedError = service.Create(newError, new ClaimsPrincipal(new ClaimsIdentity(identity)));

                if (savedError.Success == false)
                {
                    Assert.AreEqual(false, savedError.Success);
                    Assert.AreEqual("Fail", savedError.Message);
                    Assert.IsNull(savedError.Data);
                }
                else
                {
                    Assert.AreEqual(true, savedError.Success);
                    Assert.AreEqual("Succesfully registred the error.", savedError.Message);
                    Assert.IsNotNull(savedError.Data);
                }
            }
        }
 public CentralDeErrorContextTest(CentralDeErrorContext context)
 {
     _context = context;
 }
Exemplo n.º 19
0
 private static SourceRepository CreateService(FakeContext fakeContext, CentralDeErrorContext context)
 => new SourceRepository(context, fakeContext._mapper);