Пример #1
0
        public static void Initialize(IotMgmtContext context)
        {
            context.Database.EnsureCreated();

/*
 *          // Look for any students.
 *          if (context.Students.Any())
 *          {
 *              return;   // DB has been seeded
 *          }
 *
 *          var students = new Student[]
 *          {
 *              new Student{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2019-09-01")},
 *              new Student{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2017-09-01")},
 *              new Student{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2018-09-01")},
 *              new Student{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2017-09-01")},
 *              new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2017-09-01")},
 *              new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2016-09-01")},
 *              new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2018-09-01")},
 *              new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2019-09-01")}
 *          };
 *
 *          context.Students.AddRange(students);
 *          context.SaveChanges();
 *
 *          var courses = new Course[]
 *          {
 *              new Course{CourseID=1050,Title="Chemistry",Credits=3},
 *              new Course{CourseID=4022,Title="Microeconomics",Credits=3},
 *              new Course{CourseID=4041,Title="Macroeconomics",Credits=3},
 *              new Course{CourseID=1045,Title="Calculus",Credits=4},
 *              new Course{CourseID=3141,Title="Trigonometry",Credits=4},
 *              new Course{CourseID=2021,Title="Composition",Credits=3},
 *              new Course{CourseID=2042,Title="Literature",Credits=4}
 *          };
 *
 *          context.Courses.AddRange(courses);
 *          context.SaveChanges();
 *
 *          var enrollments = new Enrollment[]
 *          {
 *              new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A},
 *              new Enrollment{StudentID=1,CourseID=4022,Grade=Grade.C},
 *              new Enrollment{StudentID=1,CourseID=4041,Grade=Grade.B},
 *              new Enrollment{StudentID=2,CourseID=1045,Grade=Grade.B},
 *              new Enrollment{StudentID=2,CourseID=3141,Grade=Grade.F},
 *              new Enrollment{StudentID=2,CourseID=2021,Grade=Grade.F},
 *              new Enrollment{StudentID=3,CourseID=1050},
 *              new Enrollment{StudentID=4,CourseID=1050},
 *              new Enrollment{StudentID=4,CourseID=4022,Grade=Grade.F},
 *              new Enrollment{StudentID=5,CourseID=4041,Grade=Grade.C},
 *              new Enrollment{StudentID=6,CourseID=1045},
 *              new Enrollment{StudentID=7,CourseID=3141,Grade=Grade.A},
 *          };
 *
 *          context.Enrollments.AddRange(enrollments);
 */
            context.SaveChanges();
        }
        private IotMgmtContext CreateDbContext(int seedCount)
        {
            var options = new DbContextOptionsBuilder <IotMgmtContext>()
                          .UseInMemoryDatabase(databaseName: "IotMgmtDatabase")
                          .Options;
            var context = new IotMgmtContext(options);

            var controller = new DeviceControllerTest(context);

            var requests = controller.GetFakeDeviceRequests(seedCount).AsQueryable();

            foreach (DeviceRequest req in requests)
            {
                context.DeviceRequest.Add(req);
            }
            context.SaveChanges();

            /*
             * var dbSet = new Mock<DbSet<DeviceRequest>>();
             * dbSet.As<IQueryable<DeviceRequest>>().Setup(m => m.Provider).Returns(requests.Provider);
             * dbSet.As<IQueryable<DeviceRequest>>().Setup(m => m.Expression).Returns(requests.Expression);
             * dbSet.As<IQueryable<DeviceRequest>>().Setup(m => m.ElementType).Returns(requests.ElementType);
             * dbSet.As<IQueryable<DeviceRequest>>().Setup(m => m.GetEnumerator()).Returns(requests.GetEnumerator());
             * context.Setup(c => c.DeviceRequest).Returns(dbSet.Object);
             */
            /*
             * context.Setup(c => c.DeviceRequest).Returns(dbSet.Object);
             */
            //            var service = new Mock<IDeviceRequestService>();
            //            service.Setup(x => x.AllRequests()).Returns(requests);
            return(context);
        }
        public async void DeviceWhitelisting()
        {
            string strKey1 = "12345678";
            string strKey2 = "12345679";

            IotMgmtContext       dbContext  = CreateDbContext(0);
            DeviceControllerTest controller = new DeviceControllerTest(dbContext);

            var results = await controller.GetRequests();

            //Initially we Don't expect any values in the database
            Assert.True(0 == results.Value.Count(), "The was not empty when starting the test");

            await controller.RequestAccess(strKey1);

            results = await controller.GetRequests();

            //Verify that request was saved
            Assert.True(1 == results.Value.Count(), "Request for whitelisting failed");


            await controller.RequestAccess(strKey1);

            results = await controller.GetRequests();

            //Verify that same request was not saved
            Assert.True(1 == results.Value.Count(), "");


            await controller.RequestAccess(strKey2);

            results = await controller.GetRequests();

            //Verify that same request was not saved
            Assert.True(2 == results.Value.Count(), "Failed to save second whitelist request");


            //TODO:: Approve


            //TODO:: Same request again
        }
Пример #4
0
 public IndexModel(IotMgmtContext context)
 {
     _context = context;
 }
Пример #5
0
 public DeviceControllerTest(IotMgmtContext context)
     : base(context)
 {
 }
Пример #6
0
 public DeviceController(IotMgmtContext context)
 {
     _context = context;
 }
 public DeviceRequestService(IotMgmtContext dbContext)
 {
     _dbContext = dbContext;
 }