コード例 #1
0
    static void Main()
    {
        byte[] x = { 1, 2, 3 };
        byte[] y = { 1, 2, 3 };
        byte[] z = { 4, 5, 6 };

        var comparer = new ArrayEqualityComparer <byte>();

        Console.WriteLine(comparer.GetHashCode(x));
        Console.WriteLine(comparer.GetHashCode(y));
        Console.WriteLine(comparer.GetHashCode(z));
        Console.WriteLine(comparer.Equals(x, y));
        Console.WriteLine(comparer.Equals(x, z));
    }
コード例 #2
0
        /// <summary>
        /// Loads the current RecordSet from \\Connections\DummyConnection\Tables\LAG\Articles
        /// This can be used to verify that modifications worked.
        /// </summary>
        /// <returns></returns>
        public RecordSet LoadArticlesRecordSetFromDummyPlugin()
        {
            // load the provider plugin connection
            string[]            connectionPath = new string[] { "Connections", "DummyConnection" };
            IProviderConnection connection     = _ProviderPluginManager.Connections[connectionPath];

            string[]      endpointPath     = new string[] { "Tables", "LAG" };
            IReadEndpoint articlesEndpoint = (from e in connection.Endpoints
                                              where e is IReadEndpoint &&
                                              ArrayEqualityComparer.Equals(e.Path, endpointPath) &&
                                              e.Name == "Articles"
                                              select(IReadEndpoint) e).FirstOrDefault();

            ReadResource resource = articlesEndpoint.GetReadResource();

            // create a mocked read request

            Mock <IReadRequest> mock = new Mock <IReadRequest>();

            mock.Setup(r => r.Resource).Returns(resource);
            mock.Setup(r => r.RequestedFields).Returns(resource.Schema.Fields);

            // request all articles with all fields

            ReadResponse response = articlesEndpoint.RunReadRequest(mock.Object);

            return(response.RecordSet);
        }
コード例 #3
0
        public void Comparer_TakesIntoAccount_TheElementComparer()
        {
            var comparer = new ArrayEqualityComparer <string>(StringComparer.OrdinalIgnoreCase);
            var result   = comparer.Equals(new[] { "a" }, new[] { "A" });

            Assert.IsTrue(result);
        }
コード例 #4
0
        public void Basic_READ_Statement_Works()
        {
            string code = @"
READ \\Connections\DummyConnection\Tables\LAG\Articles 
    TO \imported\Articles
END";

            _SyneryClient.Run(code);

            // load the imported table
            ITable table = _Database.LoadTable(@"\imported\Articles");

            // load the provider plugin connection
            string[]            connectionPath = new string[] { "Connections", "DummyConnection" };
            IProviderConnection connection     = _ProviderPluginManager.Connections[connectionPath];

            string[]      endpointPath     = new string[] { "Tables", "LAG" };
            IReadEndpoint articlesEndpoint = (from e in connection.Endpoints
                                              where e is IReadEndpoint &&
                                              ArrayEqualityComparer.Equals(e.Path, endpointPath) &&
                                              e.Name == "Articles"
                                              select(IReadEndpoint) e).FirstOrDefault();

            // check whether the table is available
            Assert.IsInstanceOf <ITable>(table);

            // check whether the number of fiels is equal in the endpoint's schema and in the imported table's schema
            Assert.AreEqual(articlesEndpoint.GetReadResource().Schema.Fields.Count, table.Schema.Fields.Count);
        }
コード例 #5
0
        public void Create_Connection_With_Valid_Parameters_Works()
        {
            string code = @"
CONNECT ""Dummy"" 
    AS \\Connections\DummyConnection
    SET (
        Database.Connection.Server = ""Testserver"",
        Database.Connection.Database = ""TestDb"",
        Database.Connection.User = ""TestUser"",
        Database.Connection.Password = ""TestPassword"",
        Proffix.Tables.ShowAdditionalTables = TRUE,
        Proffix.Tables.ShowSystemTables = TRUE
    ) 
END
";

            _SyneryClient.Run(code);

            string[] connectionPath = new string[] { "Connections", "DummyConnection" };

            IProviderConnection connection = _ProviderPluginManager.Connections[connectionPath];

            var serverValue = (from a in connection.Settings.Answers
                               where ArrayEqualityComparer.Equals <string>(a.Question.Path, new string[] { "Database", "Connection" }) &&
                               a.Question.Name == "Server"
                               select a.Value).First();

            var showAdditionalTablesValue = (from a in connection.Settings.Answers
                                             where ArrayEqualityComparer.Equals <string>(a.Question.Path, new string[] { "Proffix", "Tables" }) &&
                                             a.Question.Name == "ShowAdditionalTables"
                                             select a.Value).First();

            Assert.AreEqual("Testserver", serverValue);
            Assert.AreEqual(true, showAdditionalTablesValue);
        }
コード例 #6
0
 bool _VisitNew(NewExpression x, NewExpression y)
 {
     if (x.Constructor != y.Constructor || !_ExpressionsEqual(x.Arguments, y.Arguments))
     {
         return(false);
     }
     return(ArrayEqualityComparer.Equals(x.Members, y.Members));
 }
コード例 #7
0
ファイル: BitVector.cs プロジェクト: kosorin/lunet
 private bool EqualsCore(BitVector other)
 {
     if (_capacity != other._capacity)
     {
         return(false);
     }
     return(DataComparer.Equals(_data, other._data));
 }
コード例 #8
0
        /// <summary>
        /// The header data must match the preset header data above
        /// </summary>
        /// <param name="stream">The save file stream</param>
        /// <returns></returns>
        private bool CheckHeader(FileStream stream)
        {
            var header = new byte[HeaderLength];

            stream.Read(header, 0, HeaderLength);
            var equalityComparer = new ArrayEqualityComparer <byte>();

            return(equalityComparer.Equals(header, Header));
        }
コード例 #9
0
        public void ArrayEqualityComparerReturnsFalseIfFirstAndSecondArrayElementsAreTheSameButDifferentOrder()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new[] { 1, 2, 3, 4, 5 };
            int[] second = new[] { 5, 4, 3, 2, 1 };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #10
0
        public void ArrayEqualityComparerReturnsFalseIfFirstIsShorterLengthThanSecond()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new int[0];
            int[] second = new[] { 6, 7, 8, 9, 10 };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #11
0
        public void ArrayEqualityComparerReturnsFalseIfFirstIsGreaterLengthThanSecond()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new[] { 1, 2, 3, 4, 5 };
            int[] second = new int[0];

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #12
0
        public void ArrayEqualityComparerReturnsTrueIfFirstAndSecondAreBothNull()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = null;
            int[] second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
コード例 #13
0
        public void ArrayEqualityComparerReturnsFalseIfSecondArrayIsNull()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new[] { 1, 2, 3, 4, 5 };
            int[] second = null;

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #14
0
        public void ArrayEqualityComparerReturnsFalseIfFirstArrayIsNull()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = null;
            int[] second = new[] { 6, 7, 8, 9, 10 };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #15
0
        public void ArrayEqualityComparerReturnsTrueIfArraysAreSameReference()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new[] { 1, 2, 3, 4, 5 };
            int[] second = first;

            bool result = comparer.Equals(first, second);

            Assert.IsTrue(result);
        }
コード例 #16
0
        public void ArrayEqualityComparerReturnsFalseIfFirstAndSecondArrayElementsAreNotTheSame()
        {
            var comparer = new ArrayEqualityComparer <int>();

            int[] first  = new[] { 1, 2, 3, 4, 5 };
            int[] second = new[] { 6, 7, 8, 9, 10 };

            bool result = comparer.Equals(first, second);

            Assert.IsFalse(result);
        }
コード例 #17
0
        static void Main(string[] args)
        {
            int[] x = { 1, 2, 3 };
            int[] y = { 1, 2, 3 };
            int[] z = { 4, 5, 6 };

            var comparer = new ArrayEqualityComparer <int>();

            Console.WriteLine(comparer.GetHashCode(x));
            Console.WriteLine(comparer.GetHashCode(y));
            Console.WriteLine(comparer.GetHashCode(z));
            Console.WriteLine(comparer.Equals(x, y));
            Console.WriteLine(comparer.Equals(x, z));


            Console.WriteLine();
            Console.WriteLine("Byte comparers");
            byte[] x1 = { 1, 2, 3 };
            byte[] y1 = { 1, 2, 3 };
            byte[] z1 = { 4, 5, 6 };

            var comparer1 = new ByteArrayEqualityComparer();

            Console.WriteLine(comparer1.GetHashCode(x1));
            Console.WriteLine(comparer1.GetHashCode(y1));
            Console.WriteLine(comparer1.GetHashCode(z1));
            Console.WriteLine(comparer1.Equals(x1, y1));
            Console.WriteLine(comparer1.Equals(x1, z1));

            var t = new Dictionary <byte[], string>(comparer1);

            t.Add(x1, "x");
            t.Add(z1, "z");

            Console.WriteLine($"t[y] = {t[y1]} ");

            Console.WriteLine("Press [Enter] for continue ...");
            Console.ReadLine();
        }
コード例 #18
0
        public void Create_Two_Connections_With_The_Same_ProviderPlugin()
        {
            string code = @"
CONNECT ""Dummy"" 
    AS \\Connections\FirstDummyConnection
    SET (
        Database.Connection.Server = ""FirstTestserver"",
        Database.Connection.Database = ""FirstTestDb"",
        Database.Connection.User = ""FirstTestUser"",
        Database.Connection.Password = ""FirstTestPassword"",
        Proffix.Tables.ShowAdditionalTables = TRUE,
        Proffix.Tables.ShowSystemTables = TRUE
    ) 
END

CONNECT ""Dummy"" 
    AS \\Connections\SecondDummyConnection
    SET (
        Database.Connection.Server = ""SecondTestserver"",
        Database.Connection.Database = ""SecondTestDb"",
        Database.Connection.User = ""SecondTestUser"",
        Database.Connection.Password = ""SecondTestPassword"",
        Proffix.Tables.ShowAdditionalTables = FALSE,
        Proffix.Tables.ShowSystemTables = FALSE
    ) 
END
";

            _SyneryClient.Run(code);

            string[] firstConnectionPath = new string[] { "Connections", "FirstDummyConnection" };

            IProviderConnection firstConnection = _ProviderPluginManager.Connections[firstConnectionPath];

            var firstServerValue = (from a in firstConnection.Settings.Answers
                                    where ArrayEqualityComparer.Equals <string>(a.Question.Path, new string[] { "Database", "Connection" }) &&
                                    a.Question.Name == "Server"
                                    select a.Value).First();

            string[] secondConnectionPath = new string[] { "Connections", "SecondDummyConnection" };

            IProviderConnection secondConnection = _ProviderPluginManager.Connections[secondConnectionPath];

            var secondServerValue = (from a in secondConnection.Settings.Answers
                                     where ArrayEqualityComparer.Equals <string>(a.Question.Path, new string[] { "Database", "Connection" }) &&
                                     a.Question.Name == "Server"
                                     select a.Value).First();

            Assert.AreEqual("FirstTestserver", firstServerValue);
            Assert.AreEqual("SecondTestserver", secondServerValue);
        }
コード例 #19
0
        public void Basic_READ_Statement_Works()
        {
            string code = @"
INT nextNumber = 999;
EXECUTE \\Connections\DummyConnection\Tables\LAG\Manufacturers
    GET (NextManufacturerNumber AS nextNumber)
END";

            _SyneryClient.Run(code);

            // resolve the synery variable "nextNumber"
            int testNextNumber = (int)_SyneryMemory.CurrentScope.ResolveVariable("nextNumber").Value;

            // load the provider plugin connection
            string[]            connectionPath = new string[] { "Connections", "DummyConnection" };
            IProviderConnection connection     = _ProviderPluginManager.Connections[connectionPath];

            string[]      endpointPath     = new string[] { "Tables", "LAG" };
            IReadEndpoint articlesEndpoint = (from e in connection.Endpoints
                                              where e is IReadEndpoint &&
                                              ArrayEqualityComparer.Equals(e.Path, endpointPath) &&
                                              e.Name == "Articles"
                                              select(IReadEndpoint) e).FirstOrDefault();

            ReadResource resource = articlesEndpoint.GetReadResource();

            // create a mocked read request

            Mock <IReadRequest> mock = new Mock <IReadRequest>();

            mock.Setup(r => r.Resource).Returns(resource);
            mock.Setup(r => r.RequestedFields).Returns(resource.Schema.Fields);

            // request all articles with all fields
            ReadResponse response = articlesEndpoint.RunReadRequest(mock.Object);

            // calculate the expected number from adding 1 to the highest manufacturer number
            int expectedNextNumber = response.RecordSet.Max(r => (int)r["ManufacturerNumber"]) + 1;

            Assert.AreEqual(expectedNextNumber, testNextNumber);
        }
コード例 #20
0
        bool _ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition) =>
        reference.Name.Equals(definition.Name, StringComparison.OrdinalIgnoreCase) &&
        _ReferenceMatchesDefinition(reference.Version, definition.Version) &&
        ArrayEqualityComparer.Equals(reference.GetPublicKeyToken(), definition.GetPublicKeyToken()) &&
#if NET40
        (reference.CultureInfo is null && definition.CultureInfo is null || (reference.CultureInfo?.Equals(definition.CultureInfo) ?? false))
コード例 #21
0
 private static void Compare(Node expected, Node actual)
 {
     Assert.IsTrue(comparer.Equals(expected.Id, actual.Id));
     Assert.IsTrue(comparer.Equals(expected.FromId, actual.FromId));
     Assert.IsTrue(comparer.Equals(expected.ToId, actual.ToId));
     Assert.IsTrue(comparer.Equals(expected.DataId, actual.DataId));
     Assert.AreEqual(expected.Weight, actual.Weight);
     Assert.AreEqual(expected.ModifiedOn, actual.ModifiedOn);
     Assert.AreEqual(expected.Version, actual.Version);
 }
コード例 #22
0
        public void Equals_ReturnsFalse_IfElementsDiffer()
        {
            var result = _comparer.Equals(new[] { 1, 2 }, new[] { 1, 3 });

            Assert.IsFalse(result);
        }