Exemplo n.º 1
0
        public void Handle_InvalidId_ShouldThrowNotFoundException()
        {
            var command = new DeleteReceiptItemCommand
            {
                Id = "nah",
                FinancialProjectId = "ada"
            };

            FluentActions.Awaiting(() => SendAsync(command)).Should().Throw <NotFoundException>();
        }
Exemplo n.º 2
0
        public void Handle_FinancialProjectIdEmpty_ShouldThrowValidationException()
        {
            var command = new DeleteReceiptItemCommand
            {
                Id = "asdas",
                FinancialProjectId = ""
            };

            FluentActions.Awaiting(() => SendAsync(command)).Should().Throw <ValidationException>();
        }
Exemplo n.º 3
0
        public async Task Handle_ValidId_ShouldDeleteEntity()
        {
            var project = await CreateFinancialProject();

            var receiptId = await CreateReceipt(project);

            var createCommand = new CreateReceiptItemCommand
            {
                ReceiptId = receiptId,
                Price     = 2,
                ItemGroup = (int)ItemGroup.Essentials,
                Count     = 22,
                Name      = "das",
                UserIds   = new List <string>
                {
                    User.Id,
                    SecondUser.Id
                }
            };

            var id = await SendAsync(createCommand);

            var entityBeforeDeletion = await FindAsync <ReceiptItem>(id);

            entityBeforeDeletion.Should().NotBeNull();

            var deleteCommand = new DeleteReceiptItemCommand
            {
                Id = id,
                FinancialProjectId = project
            };
            var context = CreateContext();

            var oweRecordBeforeDeleted = context.OweRecords.First(x => x.UserId == SecondUser.Id && x.OwedUserId == User.Id);

            oweRecordBeforeDeleted.Amount.Should()
            .Be(createCommand.Price * createCommand.Count / createCommand.UserIds.Count);

            await SendAsync(deleteCommand);

            context = CreateContext();

            var entity = await FindAsync <ReceiptItem>(id);

            entity.Should().BeNull();

            var oweRecord = context.OweRecords.First(x => x.UserId == SecondUser.Id && x.OwedUserId == User.Id);

            oweRecord.Amount.Should().Be(0);
        }