Ejemplo n.º 1
0
        public void Create_GivenInvalidOffer_DoesntAddItToDB()
        {
            //Arrange
            var            context          = GetContextWithData();
            var            controller       = new JobOfferController(context);
            int            jobOffersAtStart = context.JobOffers.Count();
            List <Company> companies        = context.Companies.ToList();
            //SaralyFrom > SalaryTo
            CreateViewModel cvm1 = new CreateViewModel {
                Companies = companies, Id = 5, SalaryFrom = 3000, SalaryTo = 100, JobTitle = "ExampleJobTitle", CompanyId = 1, Created = DateTime.Now, Description = "blahblah", Location = "London", ValidUntil = new DateTime(2020, 3, 12, 0, 0, 0)
            };
            //MissingValues
            CreateViewModel cvm2 = new CreateViewModel {
                Companies = companies, Id = 6, SalaryTo = 100, JobTitle = "ExampleJobTitle", Created = DateTime.Now, Description = "blahblah", Location = "London", ValidUntil = new DateTime(2020, 3, 12, 0, 0, 0)
            };
            //ValidUntil is past
            CreateViewModel cvm3 = new CreateViewModel {
                Companies = companies, Id = 7, ValidUntil = new DateTime(1999, 3, 12, 0, 0, 0), SalaryFrom = 3000, SalaryTo = 100, JobTitle = "ExampleJobTitle,", CompanyId = 1, Created = DateTime.Now, Description = "blahblah", Location = "London"
            };

            //Act
            _ = controller.Create(cvm1);
            _ = controller.Create(cvm2);
            _ = controller.Create(cvm3);
            int jobOffersAfter = context.JobOffers.Count();

            //Assert
            Assert.AreEqual(jobOffersAtStart, jobOffersAfter);
        }
Ejemplo n.º 2
0
 public async System.Threading.Tasks.Task IndexWithoutUserShouldRaiseNullReferenceException()
 {
     DataContext        context    = GetContext();
     JobOfferController controller = new JobOfferController(context, null, null, null);
     JobOffer           jobOffer   = new JobOffer();
     await Assert.ThrowsAsync <NullReferenceException>(() => controller.Edit(jobOffer));
 }
Ejemplo n.º 3
0
        public void Details_WhenThereIsJobOfferWithGivenId_ReturnsViewWithJobOffer()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "Details_HasJobOfferDetails_WhenThereIsJobOfferWithGivenId_ReturnsViewWithJobOffer")
                          .Options;


            using (var context = new DataContext(options))
            {
                context.JobOfers.Add(new JobOffer()
                {
                    ID        = 1,
                    CompanyId = 1
                });
                context.Companies.Add(new Company()
                {
                    ID = 1
                });
                context.SaveChanges();
                var controller = new JobOfferController(context);

                // Act
                var result = controller.Details(1) as ViewResult;


                //Assert
                Assert.IsInstanceOf <ViewResult>(result);
                Assert.IsNotNull(result.Model);
                Assert.IsInstanceOf <JobOffer>(result.Model);
            }
        }
Ejemplo n.º 4
0
        public void Apply_ToNonExistingOffer_ReturnsBadRequest()
        {
            //Arrange
            var context    = GetContextWithData();
            var controller = new JobOfferController(context);


            //Act
            var result = controller.Apply(-1);

            //Assert
            Assert.IsInstanceOfType(result.Result, typeof(BadRequestObjectResult));
        }
Ejemplo n.º 5
0
        public void Create_WhenModelIsNull_ThrowNullReferenceException()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "Create_WhenModelIsNull_ThrowNullReferenceException")
                          .Options;


            using (var context = new DataContext(options))
            {
                var controller = new JobOfferController(context);

                //Act and Assert
                Assert.ThrowsAsync <NullReferenceException> (() => controller.Create(null));
            }
        }
Ejemplo n.º 6
0
        public async Task Index_GivenSearchString_ReturnsCorrectViewModel()
        {
            //Arrange
            var context    = GetContextWithData();
            var controller = new JobOfferController(context);

            //Act
            var result = await controller.Index("Develo") as ViewResult;

            var model = result.Model as IndexViewModel;

            //Assert
            Assert.IsNotNull(model);
            Assert.IsNotNull(model.JobOffers[0].JobApplications);
            Assert.AreEqual(2, model.Companies.Count);
            Assert.AreEqual(2, model.JobOffers.Count);
        }
Ejemplo n.º 7
0
        public void Details_WhenThereIsNoJobOfferWithGivenId_ReturnNotFoundStatus()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "Details_WhenThereIsNoJobOfferWithGivenId_ReturnNotFoundStatus")
                          .Options;

            using (var context = new DataContext(options))
            {
                var controller = new JobOfferController(context);

                // Act
                var result = controller.Details(1);


                //Assert
                Assert.IsInstanceOf <NotFoundResult>(result);
            }
        }