public async Task Handle_ValidFields_ShouldUpdate() { var createCommand = new CreateFinancialProjectCommand { Title = "First", Users = new List <ApplicationUser> { User } }; var project = await SendAsync(createCommand); var newlyCreatedUser = await CreateNewUser("test12312312312", "hahah"); var updateCommand = new UpdateFinancialProjectCommand { Id = project.Id, Name = "Second", Users = new List <string> { User.Id, newlyCreatedUser.Id, SecondUser.Id, CreateNewUser("bla", "bla123").Result.Id, CreateNewUser("blaa", "nahhh").Result.Id }, Description = "heyy" }; await SendAsync(updateCommand); var context = CreateContext(); var entity = context.FinancialProjects .Include(x => x.FinancialProjectApplicationUsers) .Include(x => x.OweRecords) .First(x => x.Id == project.Id); entity.Should().NotBeNull(); entity.Title.Should().Be(updateCommand.Name); entity.FinancialProjectApplicationUsers.Count.Should().Be(5); entity.FinancialProjectApplicationUsers.FirstOrDefault(x => x.UserId == newlyCreatedUser.Id).Should().NotBeNull(); entity.OweRecords.Count.Should().Be(20); entity.Description.Should().Be(updateCommand.Description); var recordFrom = entity.OweRecords.FirstOrDefault(x => x.UserId == newlyCreatedUser.Id); var recordTo = entity.OweRecords.FirstOrDefault(x => x.OwedUserId == newlyCreatedUser.Id); recordFrom.Should().NotBeNull(); recordTo.Should().NotBeNull(); entity.LastModified.Should().NotBeNull(); entity.LastModified.Should().BeCloseTo(DateTime.Now, 10000); entity.LastModifiedBy.Should().NotBeNull(); entity.LastModifiedBy.Should().Be(User.Id); }
public async Task Handle_OverMaxTitleLength_ShouldThrowValidationException() { var command = new CreateFinancialProjectCommand { Title = "asdaohsfgdouhdsfgouhifgdoijgfdojifdgoijfgdjoifdgojifgdjoigdfjoiogjfdiojigdfjfodgoidfjogidfjoigjiodfjgodfoigjodfigiodfiogjdiofgiodfgjdfo", Users = new List <ApplicationUser> { await RunAsDefaultUserAsync() } }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task Handle_EmptyTitle_ShouldThrowValidationException() { var command = new CreateFinancialProjectCommand { Title = "", Users = new List <ApplicationUser> { await RunAsDefaultUserAsync() } }; FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task <ActionResult> CreateProject(CreateFinancialProjectModel model) { var command = new CreateFinancialProjectCommand { Title = model.Name, Users = await _identity.GetUsersByIds(model.Users), Description = model.Description }; var project = await Mediator.Send(command); return(PartialView("Partial/FinancialProjectCard", project)); }
public async Task Handle_RemoveUser_ShouldUpdate() { var createCommand = new CreateFinancialProjectCommand { Title = "First", Users = new List <ApplicationUser> { User, SecondUser } }; var project = await SendAsync(createCommand); var updateCommand = new UpdateFinancialProjectCommand { Id = project.Id, Name = "Second", Users = new List <string> { User.Id, }, Description = "nahhh" }; await SendAsync(updateCommand); var context = CreateContext(); var entity = context.FinancialProjects .Include(x => x.FinancialProjectApplicationUsers) .Include(x => x.OweRecords) .First(x => x.Id == project.Id); entity.Should().NotBeNull(); entity.Title.Should().Be(updateCommand.Name); entity.FinancialProjectApplicationUsers.Count.Should().Be(1); entity.FinancialProjectApplicationUsers.FirstOrDefault(x => x.UserId == SecondUser.Id).Should().BeNull(); entity.OweRecords.Count.Should().Be(0); entity.Description.Should().Be(updateCommand.Description); var recordFrom = entity.OweRecords.FirstOrDefault(x => x.UserId == SecondUser.Id); var recordTo = entity.OweRecords.FirstOrDefault(x => x.OwedUserId == SecondUser.Id); recordFrom.Should().BeNull(); recordTo.Should().BeNull(); entity.LastModified.Should().NotBeNull(); entity.LastModified.Should().BeCloseTo(DateTime.Now, 10000); entity.LastModifiedBy.Should().NotBeNull(); entity.LastModifiedBy.Should().Be(User.Id); }
protected async Task <string> CreateFinancialProject() { var createCommand = new CreateFinancialProjectCommand { Title = ProjectName, Users = new List <ApplicationUser> { User, SecondUser } }; var result = await SendAsync(createCommand); return(result.Id); }
public async Task Handle_Create_ShouldCreateFinancialProject() { var command = new CreateFinancialProjectCommand { Title = "Wooow", Users = new List <ApplicationUser> { User, SecondUser }, Description = "heyy" }; var project = await SendAsync(command); var context = CreateContext(); var entity = context.FinancialProjects .Include(x => x.FinancialProjectApplicationUsers) .Include(x => x.OweRecords) .FirstOrDefault(x => x.Id == project.Id); var oweRecords = context.OweRecords.Where(x => x.FinancialProjectId == project.Id); oweRecords.Should().NotBeNull(); oweRecords.Count().Should().Be(2); await context.DisposeAsync(); entity.Should().NotBeNull(); entity.Title.Should().Be(command.Title); entity.FinancialProjectApplicationUsers.FirstOrDefault(x => x.UserId == User.Id).Should().NotBeNull(); var record = entity.OweRecords.FirstOrDefault(x => x.UserId == User.Id); record.Should().NotBeNull(); record.Amount.Should().Be(0); record.FinancialProjectId.Should().Be(project.Id); entity.CreatedBy.Should().Be(User.Id); entity.Description.Should().Be(command.Description); entity.Created.Should().BeCloseTo(DateTime.Now, 10000); entity.FinancialProjectApplicationUsers.First().FinancialProjectId.Should().Be(project.Id); }
public async Task Handle_InvalidUserId_ShouldThrowNotFoundException() { var createCommand = new CreateFinancialProjectCommand { Title = "Create", Users = new List <ApplicationUser> { User } }; await SendAsync(createCommand); var query = new GetFinancialProjectsByUserIdQuery { UserId = "ads" }; FluentActions.Invoking(async() => await SendAsync(query)).Should().Throw <NotFoundException>(); }
public async Task Handle_ValidUserId_ShouldReturnProject() { var createCommand = new CreateFinancialProjectCommand { Title = "Create", Users = new List <ApplicationUser> { User } }; var project = await SendAsync(createCommand); var createReceipt = new CreateReceiptCommand { FinancialProjectId = project.Id, Location = "Title", DateVisited = DateTime.Now }; var receiptId = await SendAsync(createReceipt); var query = new GetFinancialProjectsByUserIdQuery { UserId = User.Id }; var model = await SendAsync(query); model.Should().NotBeNull(); model.FinancialProjects.First().Users.First().Id.Should().Be(User.Id); model.FinancialProjects.First().Title.Should().Be(createCommand.Title); model.FinancialProjects.First().Receipts.First().Id.Should().Be(receiptId); model.FinancialProjects.First().Id.Should().Be(project.Id); model.FinancialProjects.First().Receipts.First().Location.Should().Be(createReceipt.Location); model.FinancialProjects.First().CreatedBy.Should().Be(User.Id); model.FinancialProjects.First().Receipts.First().DateVisited.Should().BeCloseTo(DateTime.Now, 1000); }
public void Handle_InvalidFields_ShouldThrowValidationException() { var command = new CreateFinancialProjectCommand(); FluentActions.Invoking(async() => await SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task Handle_ValidProjectId_ShouldReturnProject() { var createCommand = new CreateFinancialProjectCommand { Title = "test", Users = new List <ApplicationUser> { User, SecondUser } }; var project = await SendAsync(createCommand); var receiptId = await CreateReceipt(project.Id); var createReceipt = new CreateReceiptCommand { FinancialProjectId = project.Id, Location = "Title", DateVisited = DateTime.Today.AddDays(-5), }; await SendAsync(createReceipt); var receiptItemCommand = new CreateReceiptItemCommand { Count = 5, Price = 2, Name = "test", ItemGroup = (int)ItemGroup.Essentials, ReceiptId = receiptId, UserIds = new List <string> { SecondUser.Id } }; var receiptItemId = await SendAsync(receiptItemCommand); var query = new GetFinancialProjectByIdQuery { ProjectId = project.Id }; var model = await SendAsync(query); model.Should().NotBeNull(); model.Receipts.First().Id.Should().Be(receiptId); model.Receipts.Count.Should().Be(2); model.Receipts.First().Location.Should().Be("Title"); model.Receipts.First().DateVisited.Should().BeCloseTo(DateTime.Now, 10000); model.Receipts.First().Items.First().Id.Should().Be(receiptItemId); model.Receipts.First().Items.First().Users.FirstOrDefault(x => x.Id == SecondUser.Id).Should().NotBeNull(); model.Receipts.First().Items.First().ItemGroup.Value.Should().Be(receiptItemCommand.ItemGroup); model.Users.FirstOrDefault(x => x.Id == SecondUser.Id).Owed.Should().Be(-10); model.Id.Should().Be(project.Id); model.Created.Should().BeCloseTo(DateTime.Now, 1000); model.Users.FirstOrDefault(x => x.Id == User.Id).Should().NotBeNull(); model.Title.Should().Be(project.Title); model.LastModified.Should().Be(null); }