Ejemplo n.º 1
0
        public void Add_OK()
        {
            Ctx = new TestPlatformDBEntities();
            Ctx.Tests.Add(TestMapper.MapBizToDal(_test));

            Ctx.Users.Add(new User
            {
                Id       = 0,
                Username = "******",
                Password = "******"
            });

            AdministratedTestRepository repo = new AdministratedTestRepository(Ctx);
            AdministratedTestService    administratedTestService = new AdministratedTestService(repo);
            var adTest = administratedTestService.AdministratedTest_Builder(TestMapper.MapDalToBiz(Ctx.Tests.Find(1)), "Daniele Tulli");

            administratedTestService.Add(adTest);

            var ad = repo.GetAdministratedTestById(1);

            ad.Should()
            .NotBeNull()
            .And
            .Be(ad.Id == 1);
        }
Ejemplo n.º 2
0
 public void AddNewTest(TestBusiness test)
 {
     using (TestRepository _repo = new TestRepository())
     {
         if (string.IsNullOrWhiteSpace(test.URL))
         {
             throw new Exception("Test not saved");
         }
         _repo.SaveTest(TestMapper.MapBizToDal(test));
     }
 }
Ejemplo n.º 3
0
        public void AdministratedTestMapper_OK()
        {
            Ctx = new TestPlatformDBEntities();
            Ctx.Tests.Add(TestMapper.MapBizToDal(_test));
            AdministratedTestRepository repo = new AdministratedTestRepository(Ctx);
            AdministratedTestService    administratedTestService = new AdministratedTestService(repo);
            var adTest = administratedTestService.AdministratedTest_Builder(TestMapper.MapDalToBiz(Ctx.Tests.Find(1)), "Daniele Tulli");

            var dao = AdministratedTestMapper.MapDomainToDao(adTest);

            //Assert.AreEqual(dao, adTest);
        }
Ejemplo n.º 4
0
        public void AdministratedTest_Builder_OK()
        {
            Ctx = new TestPlatformDBEntities();
            Ctx.Tests.Add(TestMapper.MapBizToDal(_test));
            AdministratedTestRepository repo = new AdministratedTestRepository(Ctx);
            AdministratedTestService    administratedTestService = new AdministratedTestService(repo);
            var adTest = administratedTestService.AdministratedTest_Builder(TestMapper.MapDalToBiz(Ctx.Tests.Find(1)), "Daniele Tulli");

            adTest.AdministratedQuestions.Should()
            .NotBeNull()
            .And
            .HaveCount(1);
        }
Ejemplo n.º 5
0
        public void GetAdministratedTestById_OK()
        {
            Ctx = new TestPlatformDBEntities();
            Ctx.Tests.Add(TestMapper.MapBizToDal(_test));

            AdministratedTestRepository repo = new AdministratedTestRepository(Ctx);
            AdministratedTestService    administratedTestService = new AdministratedTestService(repo);
            var adTest = administratedTestService.AdministratedTest_Builder(TestMapper.MapDalToBiz(Ctx.Tests.Find(1)), "Daniele Tulli");

            var result = administratedTestService.GetAdministratedTestById(0);

            Assert.AreEqual(result.Id, adTest.Id);
        }
Ejemplo n.º 6
0
        public void UpdateTest(TestBusiness test)
        {
            if (test == null)
            {
                throw new NullReferenceException("No test to update");
            }

            Test mappedTest = TestMapper.MapBizToDal(test);

            Test testToUpdate = _ctx.Tests.FirstOrDefault(t => t.Id == test.Id);

            testToUpdate.URL                = mappedTest.URL;
            testToUpdate.User               = mappedTest.User;
            testToUpdate.Date               = mappedTest.Date;
            testToUpdate.UserId             = mappedTest.UserId;
            testToUpdate.AdministratedTests = mappedTest.AdministratedTests;
            testToUpdate.Questions          = mappedTest.Questions;

            _ctx.SaveChanges();
        }