示例#1
0
        public async Task Test_UpsertIncomes_Fail_BadArgument()
        {
            _savingsServices.Setup(i => i.UpsertSavings(It.IsAny <List <BudgetSavingsModel> >()))
            .ThrowsAsync(new ArgumentException("This is a service argument exception"));

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.UpsertSavings(new UpsertSavingsRequest()
            {
                Savings = new List <Saving>()
                {
                    new Saving()
                    {
                        Id         = 5,
                        UserId     = 4,
                        Amount     = 500,
                        SavingType = "random string"
                    },
                    new Saving()
                    {
                        Id         = 5,
                        UserId     = 4,
                        Amount     = 500,
                        SavingType = "random string"
                    }
                }
            });

            Assert.NotNull(response);
            Assert.AreEqual(400, ((ObjectResult)response).StatusCode);
        }
示例#2
0
        public async Task Test_UpsertSavings_Success()
        {
            _savingsServices.Setup(i => i.UpsertSavings(It.IsAny <List <BudgetSavingsModel> >()))
            .Returns(Task.CompletedTask);

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.UpsertSavings(new UpsertSavingsRequest()
            {
                Savings = new List <Saving>()
                {
                    new Saving()
                    {
                        Id         = 5,
                        UserId     = 4,
                        Amount     = 500,
                        SavingType = "random string"
                    },
                    new Saving()
                    {
                        Id         = 5,
                        UserId     = 4,
                        Amount     = 500,
                        SavingType = "random string"
                    }
                }
            });

            Assert.NotNull(response);
            Assert.AreEqual(200, ((OkResult)response).StatusCode);
        }
示例#3
0
        public async Task Test_AddNewSavings_Fail_BadRequest()
        {
            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.AddNewSaving(null);

            Assert.NotNull(response);
            Assert.AreEqual(400, ((ObjectResult)response).StatusCode);
        }
示例#4
0
        public async Task Test_GetAllSavingsByUserId_Fail_BadArgument()
        {
            _savingsServices.Setup(s => s.GetAllSavingsByUserId(It.IsAny <long>()))
            .ThrowsAsync(new ArgumentException("Bad argument"));
            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.GetAllSavingsByUserId(1);

            Assert.NotNull(response);
            Assert.AreEqual(400, ((ObjectResult)response).StatusCode);
        }
示例#5
0
        public async Task Test_GetAllSavingsByUserID_Success()
        {
            _savingsServices.Setup(s => s.GetAllSavingsByUserId(It.IsAny <long>()))
            .ReturnsAsync(new List <BudgetSavingsModel>());

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.GetAllSavingsByUserId(1);

            Assert.NotNull(response);
            Assert.AreEqual(200, ((OkObjectResult)response).StatusCode);
        }
示例#6
0
        public async Task Test_UpdateSavings_Fail_InternalError()
        {
            _savingsServices.Setup(s => s.UpdateSaving(It.IsAny <long>(), It.IsAny <decimal>()))
            .ThrowsAsync(new Exception("Internal Error"));

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.UpdateSaving(new UpdateSavingRequest()
            {
                SavingsId = 1, SavingsAmount = 5
            });

            Assert.NotNull(response);
            Assert.AreEqual(500, ((ObjectResult)response).StatusCode);
        }
示例#7
0
        public async Task Test_UpdateSaving_Success()
        {
            _savingsServices.Setup(s => s.UpdateSaving(It.IsAny <long>(), It.IsAny <decimal>()))
            .Returns(Task.CompletedTask);

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.UpdateSaving(new UpdateSavingRequest()
            {
                SavingsId = 1, SavingsAmount = 5
            });

            Assert.NotNull(response);
            Assert.AreEqual(200, ((OkResult)response).StatusCode);
        }
示例#8
0
        public async Task Test_RemoveSavings_Fail_BadArgument()
        {
            _savingsServices.Setup(s => s.RemoveSaving(It.IsAny <long>()))
            .ThrowsAsync(new ArgumentException("Bad Argument"));

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.RemoveSaving(new RemoveSavingRequest()
            {
                SavingsId = 1
            });

            Assert.NotNull(response);
            Assert.AreEqual(400, ((ObjectResult)response).StatusCode);
        }
示例#9
0
        public async Task Test_AddNewSavings_Fail_InternalError()
        {
            _savingsServices.Setup(s => s.AddNewSaving(It.IsAny <BudgetSavingsModel>()))
            .ThrowsAsync(new Exception("Internal Error"));

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.AddNewSaving(new AddNewSavingRequest()
            {
                UserId        = 1,
                SavingsType   = "Money Market",
                SavingsAmount = 50
            });

            Assert.NotNull(response);
            Assert.AreEqual(500, ((ObjectResult)response).StatusCode);
        }
示例#10
0
        public async Task Test_AddNewSavings_Success()
        {
            _savingsServices.Setup(s => s.AddNewSaving(It.IsAny <BudgetSavingsModel>()))
            .Returns(Task.CompletedTask);

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.AddNewSaving(new AddNewSavingRequest()
            {
                UserId        = 1,
                SavingsType   = "Money Market",
                SavingsAmount = 50
            });

            Assert.NotNull(response);
            Assert.AreEqual(201, ((StatusCodeResult)response).StatusCode);
        }
示例#11
0
        public async Task Test_UpsertIncomes_Fail_EmptyIncomeObjects()
        {
            _savingsServices.Setup(i => i.UpsertSavings(It.IsAny <List <BudgetSavingsModel> >()))
            .Returns(Task.CompletedTask);

            var controller = new BudgetSavingsController(_savingsServices.Object);
            var response   = await controller.UpsertSavings(new UpsertSavingsRequest()
            {
                Savings = new List <Saving>()
                {
                    new Saving()
                    {
                    },
                    new Saving()
                    {
                    }
                }
            });

            Assert.NotNull(response);
            Assert.AreEqual(400, ((ObjectResult)response).StatusCode);
        }