Exemplo n.º 1
0
        public void Should_Create_New_Level()
        {
            var fakeContext = new FakeContext("CreateNewLevel");

            var fakeLevel = new Level();

            fakeLevel.Name = "full name";

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository    = new LevelRepository(context);
                var mockValidator = new Mock <IValidator <Level> >(MockBehavior.Strict);

                mockValidator
                .Setup(x => x.Validate(fakeLevel))
                .Returns(new FluentValidation.Results.ValidationResult());

                var service = new LevelService(repository, mockValidator.Object);
                var actual  = service.Create(fakeLevel);
                var id      = actual.Id;

                Assert.NotEqual(0, id);
                repository.Dispose();
            }
        }
Exemplo n.º 2
0
        public void Should_Return_All_Level_In_Db()
        {
            var fakeContext = new FakeContext("GetAllLevel");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var levelCountIndDb = context.Level.Count();
                var repository      = new LevelRepository(context);

                Assert.Equal(levelCountIndDb, repository.GetAll().Count());
                repository.Dispose();
            }
        }
Exemplo n.º 3
0
        public void Should_Return_Right_Level_When_Find_By_Id_In_Db(int id)
        {
            var fakeContext = new FakeContext("LevelById");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var expected   = fakeContext.GetFakeData <Level>().Find(x => x.Id == id);
                var repository = new LevelRepository(context);
                var actual     = repository.GetById(id);

                Assert.Equal(expected, actual, new LevelIdComparer());
                repository.Dispose();
            }
        }
Exemplo n.º 4
0
        public void Should_Update_Level_In_Db(int id)
        {
            var fakeContext = new FakeContext("UpdateLevel");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new LevelRepository(context);
                var currentLevel = repository.GetById(id);

                currentLevel.Name = "123abc";
                repository.Update(currentLevel);
                Assert.Equal("123abc", repository.GetById(id).Name);
                repository.Dispose();
            }
        }
Exemplo n.º 5
0
        public void Should_Return_All_Levels()
        {
            var fakeContext = new FakeContext("GetAllLevels");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var levelCountIndDb = context.Level.Count();
                var repository      = new LevelRepository(context);
                var validator       = new LevelValidator();
                var service         = new LevelService(repository, validator);

                Assert.Equal(levelCountIndDb, service.GetAll().Count());
                repository.Dispose();
            }
        }
Exemplo n.º 6
0
        public void Should_Update_Existing_Level(int id)
        {
            var fakeContext = new FakeContext("UpdateLevel");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository  = new LevelRepository(context);
                var validator   = new LevelValidator();
                var service     = new LevelService(repository, validator);
                var curretLevel = service.GetById(id);

                curretLevel.Name = "Testing";
                service.Update(curretLevel);
                Assert.Equal("Testing", service.GetById(id).Name);
                repository.Dispose();
            }
        }
Exemplo n.º 7
0
        public void Should_Delete_Level()
        {
            var fakeContext = new FakeContext("DeleteLevel");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new LevelRepository(context);
                var validator    = new LevelValidator();
                var service      = new LevelService(repository, validator);
                var currentCount = context.Level.Count();

                Assert.NotEqual(0, currentCount);
                service.Delete(1);
                Assert.NotEqual(currentCount, context.Level.Count());
                repository.Dispose();
            }
        }
Exemplo n.º 8
0
        public void Should_Save_New_Level_To_Db()
        {
            var fakeContext = new FakeContext("AddNewLevel");

            var fakeLevel = new Level();

            fakeLevel.Name = "Desenvolvimento";
            fakeLevel.Id   = 4;

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository = new LevelRepository(context);
                repository.Create(fakeLevel);

                var createdLevel = repository.GetById(4);

                Assert.NotEqual(0, fakeLevel.Id);
                Assert.Equal("Desenvolvimento", createdLevel.Name);
                Assert.Equal(4, createdLevel.Id);
                repository.Dispose();
            }
        }
Exemplo n.º 9
0
        public void Should_Delete_Level_In_Db()
        {
            var fakeContext = new FakeContext("DeleteLevel");

            fakeContext.FillWith <Level>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new LevelRepository(context);
                var currentCount = context.Level.Count();
                var newLevel     = new Level();
                newLevel.Name = "Testing";
                context.Level.Add(newLevel);
                context.SaveChanges();
                var idToDelete = (from l in context.Level.ToList()
                                  where l.Id == newLevel.Id
                                  select l.Id).FirstOrDefault();

                Assert.Equal(currentCount + 1, context.Level.Count());
                repository.Delete(idToDelete);
                Assert.Equal(currentCount, context.Level.Count());
                repository.Dispose();
            }
        }
Exemplo n.º 10
0
 protected override void Dispose(bool disposing)
 {
     levelRepository.Dispose();
 }