コード例 #1
0
        public void GetLastModifiedTransactionDateIn_ReturnsTransactionDateInWhichWasLastModified_WhenCall()
        {
            // Arrange
            var transaction1 = TestObjectCreator.CreateTransaction();

            transaction1.DateIn     = DateTime.Now.AddDays(-1);
            transaction1.ModifiedOn = DateTime.Now.AddDays(-2);
            var transaction2 = TestObjectCreator.CreateTransaction();

            transaction2.DateIn     = DateTime.Now.AddDays(-2);
            transaction2.ModifiedOn = DateTime.Now.AddDays(-1);
            var fakeList = new[] {
                transaction1, transaction2
            };

            MockTransactionRepository
            .Setup(m => m.GetAll())
            .Returns(fakeList);

            // Act
            var result = Controller.GetLastModifiedTransactionDateIn().Data;
            var model  = (DateTime)result;

            // Assert
            model.Should().Be(transaction2.DateIn);
        }
コード例 #2
0
        public void GetAll_ReturnOnlyItemsWithStateExisting_WhenExistsDeletedItemsCall()
        {
            // Arrange
            var transaction1 = TestObjectCreator.CreateTransaction();
            var transaction2 = TestObjectCreator.CreateTransaction();

            transaction2.RowState = (int)RowState.Deleted;
            var transaction3 = TestObjectCreator.CreateTransaction();
            var transaction4 = TestObjectCreator.CreateTransaction();

            MockDbContext
            .Setup(x => x.Transactions)
            .Returns(new FakeDbSet <Transaction> {
                transaction1,
                transaction2,
                transaction3,
                transaction4
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(3).And
            .Contain(transaction1).And
            .Contain(transaction3).And
            .Contain(transaction4);
        }
コード例 #3
0
        public void Save_AddTransactionAndSaveChanges_WhenItIsNewItem()
        {
            // Arrange
            var transaction = new Transaction {
                Id       = Guid.Empty,
                Comment  = "comment1",
                Amount   = 100,
                Account  = TestObjectCreator.CreateAccount(),
                Category = TestObjectCreator.CreateCategory()
            };
            var fakeDbSet = new FakeDbSet <Transaction>();

            MockDbContext
            .Setup(x => x.Transactions)
            .Returns(fakeDbSet);

            // Act
            Repository.Save(transaction.Id, transaction.Comment, transaction.Amount, transaction.AccountId,
                            transaction.CategoryId, transaction.RowState, transaction.NeedConfirm);

            // Assert
            fakeDbSet.Local.Should()
            .HaveCount(1);
            fakeDbSet.Local[0].AccountId.Should().Be(transaction.AccountId);
            fakeDbSet.Local[0].CategoryId.Should().Be(transaction.CategoryId);
            fakeDbSet.Local[0].Amount.Should().Be(transaction.Amount);
            fakeDbSet.Local[0].Comment.Should().Be(transaction.Comment);
            fakeDbSet.Local[0].Id.Should().NotBeEmpty();
            fakeDbSet.Local[0].RowState.Should().Be(transaction.RowState);
            fakeDbSet.Local[0].NeedConfirm.Should().Be(transaction.NeedConfirm);
            MockDbContext.Verify(x => x.SaveChanges());
        }
コード例 #4
0
        public void Edit_SaveTransactionWithStateNeedConfirm_WhenTransactionIsWithDateInFuture()
        {
            // Arrange
            var transaction = TestObjectCreator.CreateTransaction();

            transaction.DateIn = DateTime.Now.AddDays(2);
            var savedTransaction = new Transaction();

            MockTransactionRepository
            .Setup(h => h.Save(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <Guid>(), It.IsAny <Guid>(),
                               It.IsAny <byte>(), It.IsAny <bool>()))
            .Callback <Guid, string, decimal, Guid, Guid, byte, bool>((i, c, a, ai, ci, s, nc) =>
                                                                      savedTransaction = new Transaction {
                AccountId   = ai,
                Amount      = a,
                CategoryId  = ci,
                Comment     = c,
                Id          = i,
                RowState    = s,
                NeedConfirm = nc
            });

            // Act
            var model = Controller.Edit(transaction, transaction.CategoryId, transaction.AccountId);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <RedirectToRouteResult>();
            Controller.TempData["message"].Should().NotBeNull();
            savedTransaction.NeedConfirm.Should().BeTrue();
        }
コード例 #5
0
        public void GetById_ReturnExpectedItem_WhenTransactionExists()
        {
            // Arrange
            var transaction = new Transaction {
                Id       = Guid.NewGuid(),
                Comment  = "comment",
                Amount   = 100,
                Account  = TestObjectCreator.CreateAccount(),
                Category = TestObjectCreator.CreateCategory()
            };

            MockDbContext
            .Setup(x => x.Transactions)
            .Returns(new FakeDbSet <Transaction> {
                transaction
            });

            // Act
            var items = Repository.GetById(transaction.Id);

            // Assert
            items.Should()
            .NotBeNull()
            .And
            .Be(transaction);
        }
コード例 #6
0
        public void Save_AddAccountAndSaveChanges_WhenItIsNewItem()
        {
            // Arrange
            var account   = TestObjectCreator.CreateAccount(Guid.Empty);
            var fakeDbSet = new FakeDbSet <Account>();

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(fakeDbSet);

            // Act
            Repository.Save(account.Id, account.Name, account.ParentAccountId, account.CurrencyId, account.IconPath,
                            account.RowState);

            // Assert
            fakeDbSet.Local.Should()
            .HaveCount(1);
            var item = fakeDbSet.Local[0];

            item.Name.Should().Be(account.Name);
            item.ParentAccountId.Should().Be(account.ParentAccountId);
            item.RowState.Should().Be(account.RowState);
            item.ModifiedOn.Date.Should().Be(DateTime.Now.Date);
            item.IconPath.Should().Be(account.IconPath);
            item.CurrencyId.Should().Be(account.CurrencyId);
            MockDbContext.Verify(x => x.SaveChanges());
        }
コード例 #7
0
        public void GetAll_ReturnOnlyItemsWithStateExisting_WhenExistsDeletedItemsCall()
        {
            // Arrange
            var account1 = TestObjectCreator.CreateAccount();
            var account2 = TestObjectCreator.CreateAccount();

            account2.RowState = (int)RowState.Deleted;
            var account3 = TestObjectCreator.CreateAccount();
            var account4 = TestObjectCreator.CreateAccount();

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(new FakeDbSet <Account> {
                account1,
                account2,
                account3,
                account4
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(3).And
            .Contain(account1).And
            .Contain(account3).And
            .Contain(account4);
        }
コード例 #8
0
        public void List_ReturnsExpectedCollectionOfItems_WhenCall()
        {
            // Arrange
            var fakeList = new[] {
                TestObjectCreator.CreateCategory(name: "C"),
                TestObjectCreator.CreateCategory(name: "B"),
                TestObjectCreator.CreateCategory(name: "A")
            };

            MockCategoryRepository
            .Setup(m => m.GetAll())
            .Returns(fakeList);

            // Act
            var model = (List <CategoryViewModel>)Controller.List().Model;

            // Assert
            model.Should()
            .HaveCount(3).And
            .BeInAscendingOrder(x => x.Name);
            var expectedTransaction = fakeList[0];
            var item1 = model.First(x => x.Id == expectedTransaction.Id);

            item1.Name.Should().Be(expectedTransaction.Name);
            expectedTransaction = fakeList[1];
            var item2 = model.First(x => x.Id == expectedTransaction.Id);

            item2.Name.Should().Be(expectedTransaction.Name);
            expectedTransaction = fakeList[2];
            var item3 = model.First(x => x.Id == expectedTransaction.Id);

            item3.Name.Should().Be(expectedTransaction.Name);
        }
コード例 #9
0
        public void Create_ReturnsExpectedResult_WhenCall()
        {
            // Arrange
            var fakeAccounts = new[] {
                TestObjectCreator.CreateAccount(),
                TestObjectCreator.CreateAccount()
            };

            MockAccountRepository
            .Setup(m => m.GetAll())
            .Returns(fakeAccounts);

            // Act
            var model = (Account)Controller.Create().Model;

            // Assert
            model.Should()
            .NotBeNull();
            model.Id.Should().BeEmpty();
            SelectList accounts = Controller.ViewBag.Accounts;

            accounts.Should().NotBeNull();
            var expectedAcountsCount = fakeAccounts.Length + 1;

            accounts.Items.Should().HaveCount(expectedAcountsCount);
        }
コード例 #10
0
        public void Edit_ReturnExpectedResultAndSave_WhenResetParentAccount()
        {
            // Arrange
            var parrentAccountId = Guid.Empty;
            var account          = TestObjectCreator.CreateAccount();
            var context          = new Mock <HttpContextBase>();
            var request          = new Mock <HttpRequestBase>();
            var files            = new Mock <HttpFileCollectionBase>();

            context.Setup(x => x.Request).Returns(request.Object);
            request.Setup(x => x.Files).Returns(files.Object);
            files.Setup(x => x["item-icon"]).Returns((HttpPostedFileBase)null);
            Controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), Controller);
            MockAccountRepository
            .Setup(m => m.GetById(parrentAccountId))
            .Returns((Account)null);

            // Act
            var model = Controller.Edit(account, parrentAccountId);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <RedirectToRouteResult>();
            Controller.TempData["message"].Should().NotBeNull();
            MockAccountRepository
            .Verify(x => x.Save(account.Id, account.Name, account.ParentAccountId, account.CurrencyId, account.IconPath,
                                account.RowState));
            account.ParentAccount.Should().BeNull();
            account.ParentAccountId.Should().BeNull();
        }
コード例 #11
0
        public void Edit_CanEdit_WhenAccountExists()
        {
            // Arrange
            var accountId    = Guid.NewGuid();
            var account      = TestObjectCreator.CreateAccount(accountId);
            var fakeAccounts = new[] {
                account,
                TestObjectCreator.CreateAccount()
            };

            MockAccountRepository
            .Setup(m => m.GetAll())
            .Returns(fakeAccounts);
            MockAccountRepository
            .Setup(m => m.GetById(accountId))
            .Returns(account);

            // Act
            var model = ((ViewResult)Controller.Edit(accountId)).Model;

            // Assert
            model.Should()
            .NotBeNull().And
            .Be(account);
            SelectList accounts = Controller.ViewBag.Accounts;

            accounts.Should().NotBeNull();
            var expectedAcountsCount = fakeAccounts.Length + 1;

            accounts.Items.Should().HaveCount(expectedAcountsCount);
        }
コード例 #12
0
        public void GetAll_ReturnExpectedItems_WhenCall()
        {
            // Arrange
            var transaction1 = new Transaction {
                Id       = Guid.NewGuid(),
                Comment  = "comment1",
                Amount   = 100,
                Account  = TestObjectCreator.CreateAccount(),
                Category = TestObjectCreator.CreateCategory()
            };
            var transaction2 = new Transaction {
                Id       = Guid.NewGuid(),
                Comment  = "comment2",
                Amount   = 200,
                Account  = TestObjectCreator.CreateAccount(),
                Category = TestObjectCreator.CreateCategory()
            };

            MockDbContext
            .Setup(x => x.Transactions)
            .Returns(new FakeDbSet <Transaction> {
                transaction1,
                transaction2
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(2).And
            .Contain(transaction1).And
            .Contain(transaction2);
        }
コード例 #13
0
        public void GetListOfPopularAccounts_ReturnsFourLastTransactionAccounts_WhenCall()
        {
            // Arrange
            var transaction1 = TestObjectCreator.CreateTransaction();

            transaction1.ModifiedOn = DateTime.Now.AddDays(-1);
            var transaction2 = TestObjectCreator.CreateTransaction();

            transaction2.ModifiedOn = DateTime.Now.AddDays(-2);
            var transaction3 = TestObjectCreator.CreateTransaction();

            transaction3.ModifiedOn = DateTime.Now.AddDays(-3);
            var fakeList = new[] {
                transaction1, transaction2, transaction3
            };

            MockTransactionRepository
            .Setup(m => m.GetAll())
            .Returns(fakeList);

            // Act
            var result = Controller.GetListOfPopularAccounts().Data;
            var model  = (List <Guid>)result;

            // Assert
            model.Should()
            .HaveCount(2).And
            .Contain(transaction1.AccountId).And
            .Contain(transaction2.AccountId);
        }
コード例 #14
0
        public void GetAll_ReturnOnlyItemsWithStateExisting_WhenExistsDeletedItemsCall()
        {
            // Arrange
            var category1 = TestObjectCreator.CreateCategory();
            var category2 = TestObjectCreator.CreateCategory();

            category2.RowState = (int)RowState.Deleted;
            var category3 = TestObjectCreator.CreateCategory();
            var category4 = TestObjectCreator.CreateCategory();

            MockDbContext
            .Setup(x => x.Categories)
            .Returns(new FakeDbSet <Category> {
                category1,
                category2,
                category3,
                category4
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(3).And
            .Contain(category1).And
            .Contain(category3).And
            .Contain(category4);
        }
コード例 #15
0
        public void Save_UpdateTransactionAndSaveChanges_WhenItIsExistsItem()
        {
            // Arrange
            var transactionId = Guid.NewGuid();
            var fakeDbAccount = new FakeDbSet <Account> {
                TestObjectCreator.CreateAccount(),
                TestObjectCreator.CreateAccount()
            };

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(fakeDbAccount);
            var fakeDbCategory = new FakeDbSet <Category> {
                TestObjectCreator.CreateCategory(),
                TestObjectCreator.CreateCategory()
            };

            MockDbContext
            .Setup(x => x.Categories)
            .Returns(fakeDbCategory);
            var fakeDbSet = new FakeDbSet <Transaction> {
                new Transaction {
                    Id         = transactionId,
                    Comment    = "comment",
                    Amount     = 100,
                    AccountId  = fakeDbAccount.Local[0].Id,
                    CategoryId = fakeDbCategory.Local[0].Id
                }
            };

            MockDbContext
            .Setup(x => x.Transactions)
            .Returns(fakeDbSet);
            var updateTransaction = new Transaction {
                Id         = transactionId,
                Comment    = "updayteComment",
                Amount     = 200,
                AccountId  = fakeDbAccount.Local[1].Id,
                CategoryId = fakeDbCategory.Local[1].Id,
                RowState   = (int)RowState.Deleted
            };

            // Act
            Repository.Save(updateTransaction.Id, updateTransaction.Comment, updateTransaction.Amount,
                            updateTransaction.AccountId, updateTransaction.CategoryId, updateTransaction.RowState, updateTransaction.NeedConfirm);

            // Assert
            fakeDbSet.Local.Should()
            .HaveCount(1);
            var item = fakeDbSet.Local[0];

            item.Comment.Should().Be(updateTransaction.Comment);
            item.Amount.Should().Be(updateTransaction.Amount);
            item.AccountId.Should().Be(updateTransaction.AccountId);
            item.CategoryId.Should().Be(updateTransaction.CategoryId);
            item.RowState.Should().Be(updateTransaction.RowState);
            item.ModifiedOn.Date.Should().Be(DateTime.Now.Date);
            MockDbContext.Verify(x => x.SaveChanges());
        }
コード例 #16
0
        public void Edit_ReturnExpectedResultAndSave_WhenCategoryIsValid()
        {
            // Arrange
            var category = TestObjectCreator.CreateCategory();

            // Act
            var model = Controller.Edit(category);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <RedirectToRouteResult>();
            Controller.TempData["message"].Should().NotBeNull();
            MockCategoryRepository
            .Verify(x => x.Save(category.Id, category.Name, category.DirectionTypeId, category.IconPath, category.RowState));
        }
コード例 #17
0
        public void Save_UpdateAccountAndSaveChanges_WhenItIsExistsItem()
        {
            // Arrange
            var accountId = Guid.NewGuid();
            var fakeDbSet = new FakeDbSet <Account> {
                new Account {
                    Id         = accountId,
                    Name       = "name1",
                    RowState   = (int)RowState.Existing,
                    CurrencyId = Guid.NewGuid(),
                    IconPath   = "IconPath",
                    ModifiedOn = DateTime.MinValue
                }
            };

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(fakeDbSet);
            var parentAccount = TestObjectCreator.CreateAccount();
            var updateAccount = new Account {
                Id              = accountId,
                Name            = "updayteName",
                RowState        = (int)RowState.Deleted,
                CurrencyId      = Guid.NewGuid(),
                IconPath        = "updayteIconPath",
                ParentAccount   = parentAccount,
                ParentAccountId = parentAccount.Id
            };

            // Act
            Repository.Save(updateAccount.Id, updateAccount.Name, updateAccount.ParentAccountId, updateAccount.CurrencyId,
                            updateAccount.IconPath, updateAccount.RowState);

            // Assert
            fakeDbSet.Local.Should()
            .HaveCount(1);
            var item = fakeDbSet.Local[0];

            item.Name.Should().Be(updateAccount.Name);
            item.ParentAccountId.Should().Be(updateAccount.ParentAccount.Id);
            item.RowState.Should().Be(updateAccount.RowState);
            item.ModifiedOn.Date.Should().Be(DateTime.Now.Date);
            item.IconPath.Should().Be(updateAccount.IconPath);
            item.CurrencyId.Should().Be(updateAccount.CurrencyId);
            MockDbContext.Verify(x => x.SaveChanges());
        }
コード例 #18
0
        public void Edit_CanEdit_WhenTransactionExists()
        {
            // Arrange
            var transactionId = Guid.NewGuid();
            var transaction   = TestObjectCreator.CreateTransaction(transactionId);

            MockTransactionRepository
            .Setup(m => m.GetById(transactionId))
            .Returns(transaction);
            var fakeAccounts = new[] {
                TestObjectCreator.CreateAccount(),
                TestObjectCreator.CreateAccount()
            };

            MockAccountRepository
            .Setup(m => m.GetAll())
            .Returns(fakeAccounts);
            var fakeCategories = new[] {
                TestObjectCreator.CreateCategory(),
                TestObjectCreator.CreateCategory()
            };

            MockCategoryRepository
            .Setup(m => m.GetAll())
            .Returns(fakeCategories);

            // Act
            var model = ((ViewResult)Controller.Edit(transactionId)).Model;

            // Assert
            model.Should()
            .NotBeNull().And
            .Be(transaction);
            SelectList accounts = Controller.ViewBag.Accounts;

            accounts.Should().NotBeNull();
            var expectedAcountsCount = fakeAccounts.Length + 1;

            accounts.Items.Should().HaveCount(expectedAcountsCount);
            SelectList categories = Controller.ViewBag.Categories;

            categories.Should().NotBeNull();
            var expectedCategoriesCount = fakeCategories.Length + 1;

            categories.Items.Should().HaveCount(expectedCategoriesCount);
        }
コード例 #19
0
        public void Edit_CanEdit_WhenCategoryExists()
        {
            // Arrange
            var categoryId = Guid.NewGuid();
            var category   = TestObjectCreator.CreateCategory(categoryId);

            MockCategoryRepository
            .Setup(m => m.GetById(categoryId))
            .Returns(category);

            // Act
            var model = (Category)Controller.Edit(categoryId).Model;

            // Assert
            model.Should()
            .NotBeNull().And
            .Be(category);
        }
コード例 #20
0
        public void Edit_ReturnExpectedResultAndNotSave_WhenAccountIsNotValid()
        {
            // Arrange
            var account = TestObjectCreator.CreateAccount();

            Controller.ModelState.AddModelError("error", "error");

            // Act
            var model = Controller.Edit(account, Guid.Empty);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <ViewResult>();
            MockAccountRepository
            .Verify(x => x.Save(account.Id, account.Name, account.ParentAccountId, account.CurrencyId, account.IconPath,
                                account.RowState), Times.Never);
        }
コード例 #21
0
        public void Edit_ReturnExpectedResultAndNotSave_WhenCategoryIsNotValid()
        {
            // Arrange
            var category = TestObjectCreator.CreateCategory();

            Controller.ModelState.AddModelError("error", "error");

            // Act
            var model = Controller.Edit(category);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <ViewResult>();
            MockCategoryRepository
            .Verify(x => x.Save(category.Id, category.Name, category.DirectionTypeId, category.IconPath, category.RowState),
                    Times.Never);
        }
コード例 #22
0
        public void Edit_ReturnExpectedResultAndNotSave_WhenTransactionIsNotValid()
        {
            // Arrange
            var transaction = TestObjectCreator.CreateTransaction();

            Controller.ModelState.AddModelError("error", @"error");

            // Act
            var model = Controller.Edit(transaction, transaction.CategoryId, transaction.AccountId);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <ViewResult>();
            MockTransactionRepository
            .Verify(x => x.Save(transaction.Id, transaction.Comment, transaction.Amount, transaction.AccountId,
                                transaction.CategoryId, transaction.RowState, transaction.NeedConfirm), Times.Never);
        }
コード例 #23
0
        public void List_ReturnsExpectedCollectionOfItems_WhenCall()
        {
            // Arrange
            const string dateFormat = "yyyy.MM.dd";
            var          fakeList   = new[] {
                TestObjectCreator.CreateTransaction(),
                         TestObjectCreator.CreateTransaction(),
                         TestObjectCreator.CreateTransaction()
            };

            MockTransactionRepository
            .Setup(m => m.GetAll())
            .Returns(fakeList);

            // Act
            var model = (List <TransactionViewModel>)Controller.List().Model;

            // Assert
            model.Should().HaveCount(3);
            var expectedTransaction = fakeList[0];
            var item1 = model.First(x => x.Id == expectedTransaction.Id);

            item1.Amount.Should().Be(expectedTransaction.Amount);
            item1.AccountName.Should().Be(expectedTransaction.Account.Name);
            item1.CategoryName.Should().Be(expectedTransaction.Category.Name);
            item1.Comment.Should().Be(expectedTransaction.Comment);
            item1.DateIn.Should().Be(expectedTransaction.DateIn.ToString(dateFormat));
            expectedTransaction = fakeList[1];
            var item2 = model.First(x => x.Id == expectedTransaction.Id);

            item2.Amount.Should().Be(expectedTransaction.Amount);
            item2.AccountName.Should().Be(expectedTransaction.Account.Name);
            item2.CategoryName.Should().Be(expectedTransaction.Category.Name);
            item2.Comment.Should().Be(expectedTransaction.Comment);
            item2.DateIn.Should().Be(expectedTransaction.DateIn.ToString(dateFormat));
            expectedTransaction = fakeList[2];
            var item3 = model.First(x => x.Id == expectedTransaction.Id);

            item3.Amount.Should().Be(expectedTransaction.Amount);
            item3.AccountName.Should().Be(expectedTransaction.Account.Name);
            item3.CategoryName.Should().Be(expectedTransaction.Category.Name);
            item3.Comment.Should().Be(expectedTransaction.Comment);
            item3.DateIn.Should().Be(expectedTransaction.DateIn.ToString(dateFormat));
        }
コード例 #24
0
        public void GetById_ReturnExpectedItem_WhenCategoryExists()
        {
            // Arrange
            var category = TestObjectCreator.CreateCategory();

            MockDbContext
            .Setup(x => x.Categories)
            .Returns(new FakeDbSet <Category> {
                category
            });

            // Act
            var items = Repository.GetById(category.Id);

            // Assert
            items.Should()
            .NotBeNull().And
            .Be(category);
        }
コード例 #25
0
        public void ToTransactionViewModelList_CreteExpectedCollection_WhenCall()
        {
            // Arrange
            var transactions = new List <Transaction> {
                new Transaction {
                    Id       = Guid.NewGuid(),
                    Amount   = 100,
                    Comment  = "comment1",
                    Account  = TestObjectCreator.CreateAccount(),
                    Category = TestObjectCreator.CreateCategory()
                },
                new Transaction {
                    Id       = Guid.NewGuid(),
                    Amount   = 200,
                    Comment  = "comment2",
                    Account  = TestObjectCreator.CreateAccount(),
                    Category = TestObjectCreator.CreateCategory()
                }
            };

            // Act
            var viewModel = transactions.ToTransactionViewModelList();

            // Assert
            viewModel.Should()
            .NotBeNull().And
            .HaveCount(2);
            var item1 = viewModel.First(x => x.Id == transactions[0].Id);

            item1.Id.Should().Be(transactions[0].Id);
            item1.Amount.Should().Be(transactions[0].Amount);
            item1.Comment.Should().Be(transactions[0].Comment);
            item1.AccountName.Should().Be(transactions[0].Account.Name);
            item1.CategoryName.Should().Be(transactions[0].Category.Name);
            var item2 = viewModel.First(x => x.Id == transactions[1].Id);

            item2.Id.Should().Be(transactions[1].Id);
            item2.Amount.Should().Be(transactions[1].Amount);
            item2.Comment.Should().Be(transactions[1].Comment);
            item2.AccountName.Should().Be(transactions[1].Account.Name);
            item2.CategoryName.Should().Be(transactions[1].Category.Name);
        }
コード例 #26
0
        public void GetById_ReturnExpectedItem_WhenAccountExists()
        {
            // Arrange
            var account = TestObjectCreator.CreateAccount();

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(new FakeDbSet <Account> {
                account
            });

            // Act
            var items = Repository.GetById(account.Id);

            // Assert
            items.Should()
            .NotBeNull()
            .And
            .Be(account);
        }
コード例 #27
0
        public void Edit_CanNotEdit_WhenTransactionNotExists()
        {
            // Arrange
            var unknownTransactionId = Guid.NewGuid();
            var fakeList             = new[] {
                TestObjectCreator.CreateTransaction(),
                TestObjectCreator.CreateTransaction()
            };

            MockTransactionRepository
            .Setup(m => m.GetAll())
            .Returns(fakeList);

            // Act
            var model = Controller.Edit(unknownTransactionId);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <HttpNotFoundResult>();
        }
コード例 #28
0
        public void Delete_ReturnExpectedResultAndSaveWithDeletedState_WhenCategoryIsExists()
        {
            // Arrange
            var categoryId = Guid.NewGuid();
            var category   = TestObjectCreator.CreateCategory(categoryId);

            MockCategoryRepository
            .Setup(m => m.GetById(categoryId))
            .Returns(category);

            // Act
            var model = Controller.Delete(categoryId);

            // Assert
            model.Should()
            .NotBeNull().And
            .BeOfType <RedirectToRouteResult>();
            MockCategoryRepository
            .Verify(x => x.Save(category.Id, category.Name, category.DirectionTypeId, category.IconPath, category.RowState),
                    Times.Once);
            ((RowState)category.RowState).Should().Be(RowState.Deleted);
        }
コード例 #29
0
        public void GetAll_ReturnExpectedItems_WhenCall()
        {
            // Arrange
            var account1 = TestObjectCreator.CreateAccount();
            var account2 = TestObjectCreator.CreateAccount();

            MockDbContext
            .Setup(x => x.Accounts)
            .Returns(new FakeDbSet <Account> {
                account1,
                account2
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(2).And
            .Contain(account1).And
            .Contain(account2);
        }
コード例 #30
0
        public void GetAll_ReturnExpectedItems_WhenCall()
        {
            // Arrange
            var category1 = TestObjectCreator.CreateCategory();
            var category2 = TestObjectCreator.CreateCategory();

            MockDbContext
            .Setup(x => x.Categories)
            .Returns(new FakeDbSet <Category> {
                category1,
                category2
            });

            // Act
            var items = Repository.GetAll();

            // Assert
            items.Should()
            .HaveCount(2).And
            .Contain(category1).And
            .Contain(category2);
        }