Example #1
0
        public async Task <IActionResult> EditReceipt(string id, string financialProjectId)
        {
            var query = new GetReceiptByIdQuery
            {
                ReceiptId = id
            };

            var receiptDto = await Mediator.Send(query);

            var usersQuery = new GetUsersFromFinancialProjectQuery {
                FinancialProjectId = financialProjectId
            };

            var userDtos = await Mediator.Send(usersQuery);

            var model = new CreateReceiptModel
            {
                ReceiptDto          = receiptDto,
                FinancialProjectId  = financialProjectId,
                CreateReceiptItemVm = await CreateReceiptItemVm(userDtos)
            };


            return(View(model));
        }
Example #2
0
        public void Handle_InvalidId_ShouldThrowNotFoundException()
        {
            var query = new GetReceiptByIdQuery
            {
                ReceiptId = "asdasd"
            };

            FluentActions.Invoking(async() => await SendAsync(query)).Should().Throw <NotFoundException>();
        }
Example #3
0
        public void Handle_IdIsEmpty_ShouldThrowValidationException()
        {
            var query = new GetReceiptByIdQuery
            {
                ReceiptId = ""
            };

            FluentActions.Invoking(async() => await SendAsync(query)).Should().Throw <ValidationException>();
        }
Example #4
0
        public async Task Handle_ValidReceiptId_ShouldReturnReceiptVm()
        {
            var financialProjectId = await CreateFinancialProject();

            var createCommand = new CreateReceiptCommand
            {
                FinancialProjectId = financialProjectId,
                Location           = "Title",
                DateVisited        = DateTime.Now,
                Note = "yooo a note"
            };

            var receiptId = await SendAsync(createCommand);

            var receiptItemCommand = new CreateReceiptItemCommand
            {
                Name      = "idk",
                Count     = 100,
                Price     = 1000,
                ItemGroup = 0,
                ReceiptId = receiptId,
                UserIds   = new List <string>
                {
                    User.Id,
                    SecondUser.Id
                }
            };

            var receiptItemId = await SendAsync(receiptItemCommand);


            var query = new GetReceiptByIdQuery
            {
                ReceiptId = receiptId
            };

            var model = await SendAsync(query);


            model.Should().NotBeNull();
            model.CreatedByUserId.Should().Be(User.Id);
            model.Location.Should().Be(createCommand.Location);
            model.Note.Should().Be(createCommand.Note);
            model.DateVisited.Should().BeCloseTo(DateTime.Now, 1000);
            model.CreatedByUserId.Should().Be(User.Id);
            model.CreatedByDto.Should().NotBeNull();
            model.CreatedByDto.Id.Should().Be(User.Id);
            model.Deleted.Should().BeNull();
            var item = model.Items.First();

            item.Should().NotBeNull();
            item.Id.Should().Be(receiptItemId);
            item.Count.Should().Be(receiptItemCommand.Count);
            item.Price.Should().Be(receiptItemCommand.Price);
            item.ItemGroup.Value.Should().Be(receiptItemCommand.ItemGroup);
            item.Users.Count.Should().Be(receiptItemCommand.UserIds.Count);
        }