コード例 #1
0
        public async void TestForGetVendorById()
        {
            var options = new DbContextOptionsBuilder <LeagueContext>()
                          .UseInMemoryDatabase(databaseName: "p3VendorControllerGetVendorById")
                          .Options;

            using (var context = new LeagueContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo             r                = new Repo(context, new NullLogger <Repo>());
                Logic            logic            = new Logic(r, new NullLogger <Repo>());
                VendorController vendorController = new VendorController(logic);
                var vendor = new Vendor
                {
                    VendorID   = Guid.NewGuid(),
                    VendorInfo = "chicken tenders",
                    VendorName = "bojangles"
                };

                var getVendor = await vendorController.GetVendorById(vendor.VendorID);

                Assert.IsAssignableFrom <string>((getVendor as NotFoundObjectResult).Value);

                r.Vendors.Add(vendor);
                await r.CommitSave();

                var getVendor2 = await vendorController.GetVendorById(vendor.VendorID);

                Assert.IsAssignableFrom <Vendor>((getVendor2 as OkObjectResult).Value);
            }
        }