Ejemplo n.º 1
0
            public void ThrowsExceptionWhenBudgetWithMismatchedUserIds()
            {
                // Arrange.
                this.budget.UserId = 1;
                this.userId        = 2;

                // Act.
                Exception caughtException = null;

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

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(ArgumentException), "This should be an argument exception.");
                string exceptionMessage = "A user ID is expected to match the passed in user ID for a budget.\r\nParameter name: budget.UserId";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Ejemplo n.º 2
0
            public void UpdatesBudgetInTheContext()
            {
                // Act.
                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    BudgetsRepository repository = new BudgetsRepository(context);
                    repository.Save(this.budget, this.userId);
                }

                // Assert.
                using (CheckbookContext context = new CheckbookContext(this.dbContextOptions))
                {
                    int expectedBudgetCount = 5;
                    Assert.AreEqual(expectedBudgetCount, context.Budgets.Count(), "The number of budgets should not change.");

                    Budget actual = ContextDataService.GetBudgetsSet(context)
                                    .FirstOrDefault(x => x.Id == this.budget.Id);
                    Assert.IsNotNull(actual, "A budget should be found.");

                    Budget expected = this.budget;
                    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.");
                }
            }
Ejemplo n.º 3
0
            public void ThrowsExceptionWhenIdZero()
            {
                // Arrange.
                this.budget.Id = 0;

                // Act.
                Exception caughtException = null;

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

                // Assert.
                Assert.IsNotNull(caughtException, "An exception should be thrown.");
                Assert.IsInstanceOfType(caughtException, typeof(ArgumentException), "This should be an argument exception.");
                string exceptionMessage = "A budget with a specified ID should have been used. To add a budget, use the Add method.\r\nParameter name: budget.Id";

                Assert.AreEqual(exceptionMessage, caughtException.Message, "The exception message should be correct.");
            }
Ejemplo n.º 4
0
            public void ReturnsBudgetFromContext()
            {
                // Act.
                Budget actual;

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

                // Assert.
                Assert.AreEqual(this.budget.Id, actual.Id, "The ID for the entity should match.");
            }