コード例 #1
0
ファイル: UnitTests.cs プロジェクト: cjan957/SpendingTracker
        public async Task TestCostByTrip()
        {
            using (var context = new SpendingTrackContext(options))
            {
                SpendingItem TestItem = new SpendingItem()
                {
                    Heading   = "Flight to Sydney",
                    Category  = "flight",
                    Cost      = 400,
                    TripID    = 1,
                    Currency  = "AU$",
                    CreatedAt = "",
                    ReceiptID = "",
                    Note      = "QANTAS Flight",
                };

                SpendingController spendingController = new SpendingController(context, configuration);
                IActionResult      result             = await spendingController.PostSpendingItem(TestItem) as IActionResult;

                Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));

                double result_2 = await spendingController.CostByTrip(1);

                Assert.IsTrue(result_2 == 455.89);
            }
        }
コード例 #2
0
ファイル: UnitTests.cs プロジェクト: cjan957/SpendingTracker
        public async Task TestAddNewZeroCostItem()
        {
            using (var context = new SpendingTrackContext(options))
            {
                SpendingItem TestItem = new SpendingItem()
                {
                    Heading = "Lunch at Yumekaze",
                    //what can be in the category field is restricted, see the helper function in SpendingTrack to see what's
                    //allowed to be in the category field (lunch is not permitted)
                    Category  = "food",
                    Cost      = 0,
                    TripID    = 3,
                    Currency  = "JPY",
                    CreatedAt = "",
                    ReceiptID = "",
                    Note      = "Very good sushi",
                };

                SpendingController spendingController = new SpendingController(context, configuration);
                IActionResult      result             = await spendingController.PostSpendingItem(TestItem) as IActionResult;

                //should return unprocessableentity
                Assert.IsInstanceOfType(result, typeof(UnprocessableEntityObjectResult));
            }
        }
コード例 #3
0
ファイル: UnitTests.cs プロジェクト: cjan957/SpendingTracker
        public async Task TestAddNewItem()
        {
            using (var context = new SpendingTrackContext(options))
            {
                SpendingItem TestItem = new SpendingItem()
                {
                    Heading   = "Lunch at Yumekaze",
                    Category  = "food",
                    Cost      = 65.4,
                    TripID    = 3,
                    Currency  = "JPY",
                    CreatedAt = "",
                    ReceiptID = "",
                    Note      = "Very good sushi",
                };

                SpendingController spendingController = new SpendingController(context, configuration);
                IActionResult      result             = await spendingController.PostSpendingItem(TestItem) as IActionResult;

                Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));

                var checkQuery = (from m in context.SpendingItem where m.Heading == TestItem.Heading &&
                                  m.Category == TestItem.Category &&
                                  m.Cost == TestItem.Cost &&
                                  m.TripID == TestItem.TripID &&
                                  m.Currency == TestItem.Currency &&
                                  m.CreatedAt == TestItem.CreatedAt &&
                                  m.ReceiptID == TestItem.ReceiptID &&
                                  m.Note == TestItem.Note
                                  select m);

                SpendingItem fromMockDB = context.SpendingItem.Where(x => (x.Heading == TestItem.Heading) &&
                                                                     (x.Category == TestItem.Category) && (x.Cost == TestItem.Cost) && (x.TripID == TestItem.TripID) &&
                                                                     (x.Currency == TestItem.Currency) && (x.CreatedAt == TestItem.CreatedAt) && (x.ReceiptID == TestItem.ReceiptID &&
                                                                                                                                                  (x.Note == TestItem.Note))).Single();
            }
        }