Пример #1
0
        public void CanCreateProjectAndGetDeviceVersion()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);

                    var projectDeviceVersion = ProjectDeviceActions.GetLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    projectDeviceVersion = ProjectDeviceActions.GetLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    Assert.NotNull(projectDeviceVersion);
                }
        }
        public void CanDistinguishBetweenProjectDevicesAndNonProjectDevices()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var anotherProject = new Project {
                        Name = "Test2"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };
                    var anotherDevice = new Device {
                        IpAddress = "192.168.1.2", Name = "MyOtherTestDevice"
                    };

                    project        = ProjectActions.CreateProject(project).Function(conn);
                    anotherProject = ProjectActions.CreateProject(anotherProject).Function(conn);
                    var projectDevice        = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                    var anotherProjectDevice = DeviceActions.AddDeviceToProject(anotherProject.Id, anotherDevice).Function(conn);

                    var devices = DeviceActions.GetProjectDevices(project.Id).Function(conn);

                    Assert.Equal(1, devices.Count());

                    var retrievedDevice = devices.Single();

                    Assert.Equal(device.IpAddress, retrievedDevice.IpAddress);
                    Assert.Equal(device.Name, retrievedDevice.Name);
                }
        }
Пример #3
0
        public void CanSetProjectDeviceMappingsTwice()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice        = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                    var projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    var firstMappings = new List <ProjectDeviceVersionMapping>
                    {
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 1,
                            VerticalPosition   = 1,
                            MappingOrder       = 1
                        }
                    };

                    var secondMappings = new List <ProjectDeviceVersionMapping>
                    {
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 1,
                            VerticalPosition   = 1,
                            MappingOrder       = 1,
                        },
                        new ProjectDeviceVersionMapping
                        {
                            HorizontalPosition = 2,
                            VerticalPosition   = 1,
                            MappingOrder       = 2
                        }
                    };

                    ProjectDeviceActions.SetProjectDeviceMappings(projectDeviceVersion.Id, firstMappings).Function(conn);
                    ProjectDeviceActions.SetProjectDeviceMappings(projectDeviceVersion.Id, secondMappings).Function(conn);

                    var result = ProjectDeviceActions.GetProjectDeviceMappings(projectDeviceVersion.Id).Function(conn);

                    Assert.Equal(2, result.Count());
                }
        }
        public void CanAddDeviceToProject()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);
                }
        }
Пример #5
0
        public void CanUndoProjectDeviceVersion()
        {
            using (var dbFactory = new TestDbConnectionFactory())
                using (var conn = dbFactory.Database())
                {
                    var project = new Project {
                        Name = "Test"
                    };
                    var device = new Device {
                        IpAddress = "192.168.1.1", Name = "MyTestDevice"
                    };

                    project = ProjectActions.CreateProject(project).Function(conn);
                    var projectDevice = DeviceActions.AddDeviceToProject(project.Id, device).Function(conn);

                    var projectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 100,
                        VerticalPercentage          = 100,
                        NumberOfHorizontalPixels    = 50,
                        NumberOfVerticalPixels      = 50,
                        StartAtHorizontalPercentage = 0,
                        StartAtVerticalPercentage   = 0
                    }).Function(conn);

                    var updatedProjectDeviceVersion = ProjectDeviceActions.SetLatestProjectDeviceVersion(new ProjectDeviceVersion
                    {
                        ProjectDeviceId             = projectDevice.Id,
                        HorizontalPercentage        = 99,
                        VerticalPercentage          = 99,
                        NumberOfHorizontalPixels    = 30,
                        NumberOfVerticalPixels      = 30,
                        StartAtHorizontalPercentage = 1,
                        StartAtVerticalPercentage   = 1
                    }).Function(conn);

                    var undoneProjectDeviceVersion = ProjectDeviceActions.UndoLatestProjectDeviceVersion(projectDevice.Id).Function(conn);

                    var undoEqualsOriginalProjectDeviceVersion = projectDeviceVersion.PropertiesAreEqual(undoneProjectDeviceVersion);

                    Assert.True(undoEqualsOriginalProjectDeviceVersion);
                }
        }
Пример #6
0
        public GlobalJsonResult <ProjectDevice> AddDeviceToProject(int projectId, Device device)
        {
            var result = dataAccessDispatcher.Dispatch(DeviceActions.AddDeviceToProject(projectId, device));

            return(GlobalJsonResult <ProjectDevice> .Success(System.Net.HttpStatusCode.Created, result));
        }
Пример #7
0
        public GlobalJsonResult <ProjectDevice> AddDiscoveredDeviceToProject(int projectId, [FromBody] DiscoveredDevice device)
        {
            var result = dispatcher.Dispatch(DeviceActions.AddDeviceToProject(projectId, device.Map()));

            return(GlobalJsonResult <ProjectDevice> .Success(HttpStatusCode.OK, result));
        }