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

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new StatusRepository(context);
                var validator    = new StatusValidator();
                var service      = new StatusService(repository, validator);
                var currentCount = context.Status.Count();
                var newStatus    = new Status();
                newStatus.Name = "Testing";
                service.Create(newStatus);
                var createdStatus = (from u in service.GetAll()
                                     where u.Id != 0
                                     select u).FirstOrDefault();

                Assert.NotEqual(0, currentCount);
                service.Delete(createdStatus.Id);
                Assert.Equal(currentCount, context.Status.Count());
                repository.Dispose();
            }
        }
Exemplo n.º 2
0
        public void Should_Return_All_Status()
        {
            var fakeContext = new FakeContext("GetAllStatus");

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var statusCountIndDb = context.Status.Count();
                var repository       = new StatusRepository(context);
                var validator        = new StatusValidator();
                var service          = new StatusService(repository, validator);

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

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new StatusRepository(context);
                var validator    = new StatusValidator();
                var service      = new StatusService(repository, validator);
                var curretStatus = service.GetById(id);

                curretStatus.Name = "Testing";
                service.Update(curretStatus);
                Assert.Equal("Testing", service.GetById(id).Name);
                repository.Dispose();
            }
        }
Exemplo n.º 4
0
        public void Should_Return_Right_Status_When_Find_By_Id(int id)
        {
            var fakeContext = new FakeContext("StatusById");

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var expected = fakeContext.GetFakeData <Status>().Find(x => x.Id == id);

                var repository = new StatusRepository(context);
                var validator  = new StatusValidator();
                var service    = new StatusService(repository, validator);
                var actual     = service.GetById(id);

                Assert.Equal(expected, actual, new StatusIdComparer());
                repository.Dispose();
            }
        }
Exemplo n.º 5
0
        public void Should_Create_Correct_StatusDTO_Object(int id)
        {
            var fakeContext = new FakeContext("StatusDTOTest");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository = new StatusRepository(context);
                var validator  = new StatusValidator();
                var service    = new StatusService(repository, validator);
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <AutoMapperProfile>();;
                });
                var mapper = mockMapper.CreateMapper();

                var testStatus = service.GetById(id);
                var statusDTO  = mapper.Map <Status, StatusDTO>(testStatus);

                Assert.IsType <StatusDTO>(statusDTO);
                Assert.Equal(testStatus.Name, statusDTO.Name);
            }
        }