示例#1
0
        public void Register_Should_Register_One_Value()
        {
            // Arrange
            var fakeContext = new FakeContext("Register");

            fakeContext.FillWith <Level>();
            fakeContext.FillWith <Model.Models.Environment>();
            fakeContext.FillWith <Microsservice>();

            var service = new ServiceBase <Error>(fakeContext.context);

            var entry = new Error
            {
                Title   = "entry",
                Origin  = "*****@*****.**",
                Details = "detailEntry",
                MicrosserviceClientId = new Guid("84cd83de-1809-4f3d-a92c-b263d18f4244"),
                EnviromentId          = 1,
                LevelId    = 1,
                IsArchived = false
            };

            // Act
            service.Register(entry);
            var result = fakeContext.GetFakeData <Error>().FirstOrDefault(x => x.Id == 1);

            // Assert
            Assert.NotNull(result);
            Assert.True(fakeContext.context.Errors.Count() == 1, "Should has one Error inside dbContext");
            Assert.True(fakeContext.GetFakeData <Error>().Any(x => x.Id == 1), "Should has entry with Id 1");
        }
        public void Register_Should_Add_New_Error()
        {
            // Arrange
            var fakeContext = new FakeContext("RegisterError");

            fakeContext.FillWith <Level>();
            fakeContext.FillWith <Microsservice>();
            fakeContext.FillWith <Model.Models.Environment>();

            var   context = new CentralDeErrosDbContext(fakeContext.FakeOptions);
            var   service = new ErrorService(context);
            Error entry   = new Error
            {
                Title                 = "Teste1",
                Origin                = "1.0.0.1",
                Details               = "Detail1",
                ErrorDate             = DateTime.Today,
                MicrosserviceClientId = new Guid("031c156c-c072-4793-a542-4d20840b8031"),
                EnviromentId          = 1,
                LevelId               = 1,
                IsArchived            = false
            };

            // Act
            var result = service.Register(entry);

            // Assert
            Assert.True(result.Id == 1, $"Should return new error with id 1. returned: {result.Id}");
            Assert.True(context.Errors.Count() == 1, $"Should have one error saved. > Amount: {context.Errors.Count()}");
        }
        public void Delete_Should_Remove_The_Right_Environment()
        {
            // Arrange
            using var fakeContext = new FakeContext("deleteEnvironment");
            fakeContext.FillWith <Model.Models.Environment>();

            var context = new CentralDeErrosDbContext(fakeContext.FakeOptions);
            var service = new EnvironmentService(context);

            // Act
            service.Delete(1);

            // Assert
            Assert.Null(context.Environments.Find(1));
        }