Exemple #1
0
            public void ThrowsExceptionWhenRecordFoundDoesNotBelongToTheUser()
            {
                // Arrange.
                this.budgetId = 1;
                this.userId   = 2;

                // Act.
                Exception caughtException = null;

                try
                {
                    using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                    {
                        BudgetsRepository repository = new BudgetsRepository(context);
                        repository.Get(this.budgetId, this.userId);
                    }
                }
                catch (Exception ex)
                {
                    caughtException = ex;
                }

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(NotFoundException), "This should be an argument exception.");
                string exceptionMessage = "The budget was not found.";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Exemple #2
0
            public void ReturnsBudgetFromContext()
            {
                // Arrange.
                this.budgetId = 1;
                this.userId   = 1;

                // Act.
                Budget actual;

                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    BudgetsRepository repository = new BudgetsRepository(context);
                    actual = repository.Get(this.budgetId, this.userId);
                }

                // Assert.
                Budget expected = this.entities.ElementAt(0);

                Assert.AreEqual(expected.Id, actual.Id, "The ID for the entity should match.");
                Assert.AreEqual(expected.Name, actual.Name, "The name for the entity should match.");
                Assert.AreEqual(expected.UserId, actual.UserId, "The user ID for the entity should match.");
            }