예제 #1
0
        public async Task ExpensesController_Add_Exception_Test()
        {
            var expenseTravelRepository       = new Data.Repositories.Fakes.StubIExpenseRepository();
            var notificationChannelRepository = new Data.Repositories.Fakes.StubINotificationChannelRepository();
            var notificationService           = new Services.Fakes.StubINotificationService();

            var target = new ExpensesController(expenseTravelRepository, new SecurityHelper(), notificationChannelRepository, notificationService);
            await target.Add(null);
        }
예제 #2
0
        public async Task ExpensesController_Add_ShouldNotifyManagers()
        {
            bool notificationServiceCalled     = false;
            var  expenseRepository             = new Data.Repositories.Fakes.StubIExpenseRepository();
            var  notificationChannelRepository = new Data.Repositories.Fakes.StubINotificationChannelRepository();
            var  notificationService           = new Services.Fakes.StubINotificationService();

            var newExpense = new Expense()
            {
                ExpenseId = 1,
            };

            notificationService.NewExpenseAddedNotificationChannelExpense = (notificationChannel, expense) =>
            {
                notificationServiceCalled = true;
            };

            expenseRepository.AddAsyncExpense = (expense) =>
            {
                return(Task.FromResult(10));
            };

            expenseRepository.GetAsyncInt32 = (expenseId) =>
            {
                return(Task.FromResult(new Expense
                {
                    Employee = new Employee
                    {
                        FirstName = "John",
                        LastName = "Smith"
                    }
                }));
            };

            notificationChannelRepository.GetManagersChannelsAsync = () =>
            {
                return(Task.FromResult(new List <NotificationChannel>()
                {
                    new NotificationChannel()
                }.AsEnumerable()));
            };

            var target = new ExpensesController(expenseRepository, new SecurityHelper(), notificationChannelRepository, notificationService);
            await target.Add(newExpense);

            Assert.IsTrue(notificationServiceCalled);
        }