コード例 #1
0
        public void JobApplicationServiceTests()
        {
            // Addition
            var unit = new UnitOfWork(GetInMemoryOptions());
            var jobApplicationService = new JobApplicationService(unit, new JobApplicationQueryObject(unit));
            var c1 = new JobApplication()
            {
                Text   = "Lol",
                Status = Status.Unresolved
            };

            Assert.Null(c1.Id);
            jobApplicationService.Create(c1);
            unit.SaveChanges();
            Assert.NotEqual(-1, c1.Id);
            Assert.Equal("Lol", unit.JobApplicationRepository.GetById(c1.Id ?? -1).Text);

            Seeder.Seed(unit);

            var c2 = new JobApplication()
            {
                Text = "New addition"
            };

            Assert.Null(c2.Id);
            jobApplicationService.Create(c2);
            unit.SaveChanges();
            Assert.NotEqual(-1, c2.Id);
            Assert.Equal("New addition", unit.JobApplicationRepository.GetById(c2.Id ?? -1).Text);

            // UpdateStaus
            Assert.Equal(Status.Unresolved, unit.JobApplicationRepository.GetById(c1.Id ?? -1).Status);
            jobApplicationService.UpdateStatus(c1.Id ?? -1, Status.Accepted);
            unit.SaveChanges();
            Assert.Equal(Status.Accepted, unit.JobApplicationRepository.GetById(c1.Id ?? -1).Status);

            // Delete
            int size = unit.JobApplicationRepository.GetAll().Count();

            jobApplicationService.Delete(c1.Id ?? -1);
            unit.SaveChanges();
            Assert.Equal(size - 1, unit.JobApplicationRepository.GetAll().Count());
        }