public async Task Handle_WithExistingEstimates_ReturnClientProjects() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); var estimates = Builder <Estimate> .CreateListOfSize(20) .TheFirst(10) .With(e => e.Client = clients[0]) .TheRest() .With(e => e.Client = clients[1]) .Build(); string clientName = clients[0].Name; using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .WithEstimates(estimates) .BuildScoped()) { var handler = new GetProjectsQueryHandler(db.Context); var clientEstimates = await handler.Handle(new GetProjectsQuery(db.Context.Clients.First(c => c.Name == clientName).Id), CancellationToken.None); clientEstimates.Should().NotBeNull(); clientEstimates.Count.Should().Be(10); } }
public async Task Handle_WithValidProjectDetails_CreateTheRecord() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .BuildScoped()) { var handler = new CreateEstimateCommandHandler(db.Context); await handler.Handle(new CreateEstimateCommand { ClientId = clients[0].Id, Name = "ProjectX", EstimatorEmail = "*****@*****.**", EstimatorName = "John Doe" }, CancellationToken.None); using (var varifyContext = new InMemoryDataContextBuilder().WithDbName(db.DatabaseName).Build()) { varifyContext.Estimates .Include(e => e.Client) .FirstOrDefaultAsync(c => c.ProjectName == "ProjectX" && c.Client.Id == clients[0].Id) .Should() .NotBeNull(); } } }
public async Task Handle_WithValidBackloItemDetails_UpdatesTheRecord() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); var estimates = Builder <Estimate> .CreateListOfSize(20) .All().With(x => x.Id = 0) .TheFirst(10).With(e => e.Client = clients[0]) .TheRest().With(e => e.Client = clients[1]) .Build(); var backlogItems = Builder <BacklogItem> .CreateListOfSize(30) .All().With(x => x.Id = 0) .TheFirst(10).With(bi => bi.Estimate = estimates[0]) .TheNext(10).With(bi => bi.Estimate = estimates[1]) .TheRest().With(bi => bi.Estimate = estimates[2]) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .WithEstimates(estimates) .WithBackloItems(backlogItems) .BuildScoped()) { var handler = new UpdateBacklogItemCommandHandler(db.Context); string task = "Create contact-us page"; await handler.Handle(new UpdateBackloItemCommand { BacklogItemId = backlogItems[0].Id, Task = task, Confidence = Domain.Enums.ConfidenceLevel.Low, OptimisticEstimate = 10, PessimisticEstimate = 20 }, CancellationToken.None); using (var varifyContext = new InMemoryDataContextBuilder().WithDbName(db.DatabaseName).Build()) { var updatedItem = await varifyContext.BacklogItems.FirstOrDefaultAsync(bi => bi.Task == task); updatedItem.Should().NotBeNull(); updatedItem.Task.Should().Be(task); updatedItem.Confidence.Should().Be(ConfidenceLevel.Low); updatedItem.OptimisticEstimate.Should().Be(10); updatedItem.PessimisticEstimate.Should().Be(20); } } }
public async Task Handle_WithExistingEstimates_ReturnCorrectSummary(decimal optimisticEstimate, decimal pessimisticEstimate, int teamSize) { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); var estimates = Builder <Estimate> .CreateListOfSize(20) .All().With(x => x.Id = 0) .TheFirst(10).With(e => e.Client = clients[0]) .TheRest().With(e => e.Client = clients[1]) .Build(); var backlogItems = Builder <BacklogItem> .CreateListOfSize(30) .All().With(x => x.Id = 0) .TheFirst(10).With(bi => bi.Estimate = estimates[0]) .With(bi => bi.OptimisticEstimate = optimisticEstimate) .With(bi => bi.PessimisticEstimate = pessimisticEstimate) .TheNext(10).With(bi => bi.Estimate = estimates[1]) .TheRest().With(bi => bi.Estimate = estimates[2]) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .WithEstimates(estimates) .WithBackloItems(backlogItems) .BuildScoped()) { var startDate = new System.DateTime(2000, 1, 1); // Setup mock var mockDateTimeProvider = Substitute.For <IDateTimeProvider>(); mockDateTimeProvider.Now.Returns(startDate); var handler = new GetSummaryQueryHandler(db.Context, mockDateTimeProvider); var result = await handler.Handle(new GetSummaryQuery(estimates[0].Id, teamSize), CancellationToken.None); decimal expectedOptimisticDuration = ((optimisticEstimate * 10) / 8) / teamSize; decimal expectedPessimisticDuration = ((pessimisticEstimate * 10) / 8) / teamSize; result.OptimisticDuration.Should().Be(expectedOptimisticDuration); result.PessimisticDuration.Should().Be(expectedPessimisticDuration); result.OptimisticEndDate.Should().BeSameDateAs(startDate.AddDays((double)expectedOptimisticDuration)); result.PessimisticEndDate.Should().BeSameDateAs(startDate.AddDays((double)expectedPessimisticDuration)); } }
public async Task Handle_WithEmptyClientName_ThrowsException() { using (var db = new InMemoryDataContextBuilder() .BuildScoped()) { var handler = new CreateClientCommandHandler(db.Context); await Assert.ThrowsAsync <ValidationException>(() => handler.Handle(new CreateClientCommand { Name = string.Empty, AccountManagerEmail = "*****@*****.**", AccountManagerName = "Manager One" }, CancellationToken.None)); } }
public async Task Handle_WithValidBacklogItem_CreateTheRecord() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); var estimates = Builder <Estimate> .CreateListOfSize(20) .All().With(x => x.Id = 0) .TheFirst(10).With(e => e.Client = clients[0]) .TheRest().With(e => e.Client = clients[1]) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .WithEstimates(estimates) .BuildScoped()) { var handler = new CreateBacklogItemCommandHandler(db.Context); string task = "Create home page"; await handler.Handle(new CreateBackloItemCommand { EstimateId = estimates[0].Id, Task = task, Confidence = Domain.Enums.ConfidenceLevel.High, OptimisticEstimate = 6, PessimisticEstimate = 8 }, CancellationToken.None); using (var varifyContext = new InMemoryDataContextBuilder().WithDbName(db.DatabaseName).Build()) { varifyContext.BacklogItems .Include(bi => bi.Estimate) .FirstOrDefaultAsync(bi => bi.Estimate.Id == estimates[0].Id && bi.Task == task) .Should() .NotBeNull(); } } }
public async Task Handle_WithExistingClients_ReturnAllClients() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .BuildScoped()) { var handler = new GetAllClientsQueryHandler(db.Context); var allClients = await handler.Handle(new GetAllClientsQuery(), CancellationToken.None); allClients.Should().NotBeNull(); allClients.Count.Should().Be(10); } }
public async Task Handle_WithValidClientDetails_CreateTheRecord() { using (var db = new InMemoryDataContextBuilder().BuildScoped()) { var handler = new CreateClientCommandHandler(db.Context); await handler.Handle(new CreateClientCommand { Name = "Fabrikam", AccountManagerEmail = "*****@*****.**", AccountManagerName = "Manager One" }, CancellationToken.None); using (var varifyContext = new InMemoryDataContextBuilder().WithDbName(db.DatabaseName).Build()) { varifyContext.Clients .FirstOrDefaultAsync(c => c.Name == "Fabrikam") .Should() .NotBeNull(); } } }
public async Task Handle_WithValidEstimate_GetAllBacklogItems() { var clients = Builder <Client> .CreateListOfSize(10) .All() .With((c, index) => c.AccountManager = new Domain.ValueObjects.Contact($"Email-{index}", $"DisplayName-{index}")) .With(x => x.Id = 0) .Build(); var estimates = Builder <Estimate> .CreateListOfSize(20) .All().With(x => x.Id = 0) .TheFirst(10).With(e => e.Client = clients[0]) .TheRest().With(e => e.Client = clients[1]) .Build(); var backlogItems = Builder <BacklogItem> .CreateListOfSize(30) .All().With(x => x.Id = 0) .TheFirst(10).With(bi => bi.Estimate = estimates[0]) .TheNext(10).With(bi => bi.Estimate = estimates[1]) .TheRest().With(bi => bi.Estimate = estimates[2]) .Build(); using (var db = new InMemoryDataContextBuilder() .WithClients(clients) .WithEstimates(estimates) .WithBackloItems(backlogItems) .BuildScoped()) { var handler = new GetBacklogItemsQueryHandler(db.Context); var result = await handler.Handle(new GetBacklogItemsQuery(estimates[0].Id), CancellationToken.None); result.Should().NotBeNull(); result.Count.Should().Be(10); } }