public async Task Should_Return_All_Leads_With_New_Status()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);
            var leads = await leadHandlerRepository.GetLeadsWithNewStatus();

            Assert.NotNull(leads);
            Assert.AreEqual(5, leads.Count);
        }
        public async Task Should_Update_The_Status_of_the_Lead_To_Declined()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);

            var newLeads = await leadHandlerRepository.GetLeadsWithNewStatus();

            var jobId = newLeads[0].Id;

            var response = await leadHandlerRepository.UpdateLeadStatus(jobId, LeadStatusType.Declined.ToString());

            Assert.NotNull(response);
            Assert.AreEqual(LeadStatusType.Declined.ToString(), response.Status);

            var newLeadsAfterUpdate = await leadHandlerRepository.GetLeadsWithNewStatus();

            Assert.NotNull(newLeadsAfterUpdate);
            Assert.AreEqual(newLeads.Count - 1, newLeadsAfterUpdate.Count);
        }
        public async Task Should_Return_All_New_Leads()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);

            var leads = await leadHandlerRepository.GetLeadsWithNewStatus();

            var leadInDb = dbContext.Jobs.ToList().Where(x => x.Status == LeadStatusType.New.ToString()).ToList();

            Assert.NotNull(leads);
            Assert.AreEqual(leads.Count, leadInDb.Count);
        }
Exemple #4
0
        public async Task Should_Decline_A_New_Lead()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);

            var leads = await leadHandlerRepository.GetLeadsWithNewStatus();

            var job = leads.First();

            var leadHandler = new DeclineLeadHandler(leadHandlerRepository, CreateLogger <DeclineLeadHandler>());

            var cmd  = new DeclineLeadCommand(job.Id);
            var resp = await leadHandler.Handle(cmd, new CancellationToken());

            var leadInDb = await leadHandlerRepository.GetLeadById(job.Id);

            Assert.NotNull(resp);
            Assert.AreEqual(job.Id, resp.JobId);
            Assert.AreEqual(LeadStatusType.Declined.ToString(), resp.Status);
            Assert.AreEqual(leadInDb.Price, job.Price);
            Assert.AreEqual(LeadStatusType.Declined.ToString(), leadInDb.Status);
        }
        public async Task Should_Update_The_Status_of_the_Lead_To_Accepted()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);

            var jobToBeUpdated = dbContext.Jobs.First();

            var response = await leadHandlerRepository.UpdateLeadStatus(jobToBeUpdated.Id, LeadStatusType.Accepted.ToString());

            Assert.NotNull(response);
            Assert.AreEqual(LeadStatusType.Accepted.ToString(), response.Status);

            var newLeads = await leadHandlerRepository.GetLeadsWithNewStatus();

            Assert.NotNull(newLeads);
            Assert.AreEqual(4, newLeads.Count);

            var accLeads = await leadHandlerRepository.GetLeadsWithAcceptedStatus();

            Assert.NotNull(accLeads);
            Assert.AreEqual(4, accLeads.Count);
        }
Exemple #6
0
        public async Task Should_Accept_A_New_Lead_With_Price_less_than_500()
        {
            var dbContext = await InMemoryMockDbContext.GetDatabaseContext();

            var leadHandlerRepository = new LeadHandlerRepository(dbContext);

            var leads = await leadHandlerRepository.GetLeadsWithNewStatus();

            var job = leads.Where(x => (Convert.ToInt32(x.Price) < 500)).First();

            var leadHandler = new AcceptLeadHandler(leadHandlerRepository, CreateLogger <AcceptLeadHandler>());

            var cmd  = new AcceptLeadCommand(job.Id);
            var resp = await leadHandler.Handle(cmd, new CancellationToken());

            var leadInDb = await leadHandlerRepository.GetLeadById(job.Id);

            Assert.NotNull(resp);
            Assert.AreEqual(job.Id, resp.JobId);
            Assert.AreEqual(LeadStatusType.Accepted.ToString(), resp.Status);
            Assert.AreEqual(leadInDb.Price, job.Price);
            Assert.AreEqual(LeadStatusType.Accepted.ToString(), leadInDb.Status);
        }