Ejemplo n.º 1
0
        public async Task AssertStateAsync <T>(String tableName, int id, T expectedState)
        {
            var expectedMap = (from p in typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
                               select(name: p.Name, value: p.GetValue(expectedState))
                               ).ToDictionary(x => x.name, x => x.value);

            var actualMap = await RfidDatabase.GetRecordStateByTableNameAsync(tableName, id);

            actualMap = actualMap.Where(x => expectedMap.Keys.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value);

            Assert.True(expectedMap.OrderBy(x => x.Key).SequenceEqual(actualMap.OrderBy(x => x.Key)));
        }
Ejemplo n.º 2
0
        public static async Task <HttpResponseMessage> DeleteTagAsync(String number, String authToken)
        {
            var tagId = await RfidDatabase.GetTagIdByNumberAsync(number);

            return(await PatchAsync($"/administration/api/tags/delete", new { Id = tagId }, authToken));
        }
Ejemplo n.º 3
0
        public static async Task <HttpResponseMessage> DeleteAccessPointAsync(String serialNumber, String authToken)
        {
            var id = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(serialNumber);

            return(await PatchAsync($"/administration/api/accesspoint/delete", new { Id = id }, authToken));
        }
Ejemplo n.º 4
0
        public static async Task <HttpResponseMessage> ChangeAccessPointAccessLevelAsync(String serialNumber, AccessLevel accessLevel, String authToken)
        {
            var id = await RfidDatabase.GetAccessPointIdBySerialNumberAsync(serialNumber);

            return(await PatchAsync("/administration/api/accessPoint/accesslevel", new ChangeAccessPointAccessLevelRequestModel { AccessPointId = id, AccessLevel = accessLevel }, authToken));
        }
Ejemplo n.º 5
0
        public static async Task RestMssqlAsync()
        {
            var containerName = "rfid-mssql";
            var imageName     = "rfid-mssql";

            using (var client = new DockerClientConfiguration(new Uri("http://192.168.0.105:2375")).CreateClient())
            {
                var containers = await client.Containers.ListContainersAsync(new ContainersListParameters { All = true });

                var mssqlContainer = containers.SingleOrDefault(x => x.Names.Contains($"/{containerName}"));
                if (mssqlContainer != null)
                {
                    await client.Containers.StopContainerAsync(containerName, new ContainerStopParameters());

                    await client.Containers.RemoveContainerAsync(containerName, new ContainerRemoveParameters());
                }

                await client.Containers.CreateContainerAsync(new CreateContainerParameters
                {
                    Name       = containerName,
                    Image      = imageName,
                    HostConfig = new HostConfig
                    {
                        PortBindings = new Dictionary <String, IList <PortBinding> >
                        {
                            ["1433/tcp"] = new List <PortBinding>
                            {
                                new PortBinding
                                {
                                    HostIP   = "0.0.0.0",
                                    HostPort = "1433/tcp"
                                }
                            }
                        }
                    },
                    NetworkingConfig = new NetworkingConfig
                    {
                        EndpointsConfig = new Dictionary <String, EndpointSettings>
                        {
                            ["rfid"] = new EndpointSettings
                            {
                                IPAddress = "172.18.0.3"
                            }
                        }
                    }
                });

                await client.Containers.StartContainerAsync(containerName, new ContainerStartParameters());

                // the sql server needs some time before the first connection to be open
                while (true)
                {
                    try
                    {
                        using (var connection = RfidDatabase.CreateConnection())
                        {
                            await connection.OpenAsync();
                        }

                        break;
                    }
                    catch
                    {
                        await Task.Delay(4000);
                    }
                }
            }
        }