コード例 #1
0
        public void ID_Intern_FindOrCreate_derived_class()
        {
            Interner <int, A> interner = new Interner <int, A>();
            var obj1 = new A();
            var obj2 = new B();
            var obj3 = new B();

            var r1 = interner.FindOrCreate(1, () => obj1);

            Assert.AreEqual(obj1, r1, "Objects should be equal");
            Assert.AreSame(obj1, r1, "Objects should be same / intern'ed");

            var r2 = interner.FindOrCreate(2, () => obj2);

            Assert.AreEqual(obj2, r2, "Objects should be equal");
            Assert.AreSame(obj2, r2, "Objects should be same / intern'ed");

            // FindOrCreate should not replace instances of same class
            var r3 = interner.FindOrCreate(2, () => obj3);

            Assert.AreSame(obj2, r3, "FindOrCreate should return previous object");
            Assert.AreNotSame(obj3, r3, "FindOrCreate should not replace previous object of same class");

            // FindOrCreate should not replace cached instances with instances of most derived class
            var r4 = interner.FindOrCreate(1, () => obj2);

            Assert.AreSame(obj1, r4, "FindOrCreate return previously cached object");
            Assert.AreNotSame(obj2, r4, "FindOrCreate should not replace previously cached object");

            // FindOrCreate should not replace cached instances with instances of less derived class
            var r5 = interner.FindOrCreate(2, () => obj1);

            Assert.AreNotSame(obj1, r5, "FindOrCreate should not replace previously cached object");
            Assert.AreSame(obj2, r5, "FindOrCreate return previously cached object");
        }
コード例 #2
0
        public void ID_Intern_derived_class()
        {
            Interner <int, A> interner = new Interner <int, A>();
            var obj1 = new A();
            var obj2 = new B();
            var obj3 = new B();

            var r1 = interner.InternAndUpdateWithMoreDerived(1, obj1);

            Assert.AreEqual(obj1, r1, "Objects should be equal");
            Assert.AreSame(obj1, r1, "Objects should be same / intern'ed");

            var r2 = interner.InternAndUpdateWithMoreDerived(2, obj2);

            Assert.AreEqual(obj2, r2, "Objects should be equal");
            Assert.AreSame(obj2, r2, "Objects should be same / intern'ed");

            // Interning should not replace instances of same class
            var r3 = interner.InternAndUpdateWithMoreDerived(2, obj3);

            Assert.AreSame(obj2, r3, "Interning should return previous object");
            Assert.AreNotSame(obj3, r3, "Interning should not replace previous object of same class");

            // Interning should return instances of most derived class
            var r4 = interner.InternAndUpdateWithMoreDerived(1, obj2);

            Assert.AreSame(obj2, r4, "Interning should return most derived object");
            Assert.AreNotSame(obj1, r4, "Interning should replace cached instances of less derived object");

            // Interning should not return instances of less derived class
            var r5 = interner.InternAndUpdateWithMoreDerived(2, obj1);

            Assert.AreNotSame(obj1, r5, "Interning should not return less derived object");
            Assert.AreSame(obj2, r5, "Interning should return previously cached instances of more derived object");
        }
コード例 #3
0
        public async Task LCC_CrossThread_Dictionary()
        {
            const int NumLoops = 1000;

            string name1 = "Name" + random.Next();
            string data1 = "Main";

            var dict = new Dictionary <string, string>();

            dict[name1] = data1;
            CallContext.LogicalSetData(name1, dict);

            var result0 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);

            Assert.AreEqual(data1, result0[name1], "LCC.GetData-Main");

            Task[] promises = new Task[NumLoops];
            for (int i = 0; i < NumLoops; i++)
            {
                string str = i.ToString(CultureInfo.InvariantCulture);
                promises[i] = Task.Run(async() =>
                {
                    var result1 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
                    Assert.AreSame(dict, result1, "Same object LCC.GetData-Task.Run-Get" + str);
                    Assert.AreEqual(data1, result1[name1], "LCC.GetData-Task.Run-Get-" + str);

                    await Task.Delay(5);

                    var dict2 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
                    Assert.AreSame(dict, dict2, "Same object LCC.GetData-Task.Run-Get" + str);
                    Assert.AreEqual(data1, dict2[name1], "LCC.GetData-Task.Run-Get-" + str);

                    // Set New Dictionary
                    var dict3    = new Dictionary <string, string>();
                    dict3[name1] = str;
                    CallContext.LogicalSetData(name1, dict3);

                    var result3 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
                    Assert.AreSame(dict3, result3, "Same object LCC.GetData-Task.Run-Set-1-" + str);
                    Assert.AreEqual(str, result3[name1], "LCC.GetData-Task.Run-Set-" + str);

                    await Task.Delay(5);

                    result3 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
                    Assert.AreSame(dict3, result3, "Same object LCC.GetData-Task.Run-Set-1-" + str);
                    Assert.AreEqual(str, result3[name1], "LCC.GetData-Task.Run-Set-" + str);

                    await Task.Delay(5);
                    result3 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
                    Assert.AreSame(dict3, result3, "Same object LCC.GetData-Task.Run-Set-2-" + str);
                    Assert.AreEqual(str, result3[name1], "LCC.GetData-Task.Run-Set-" + str);
                });
            }
            await Task.WhenAll(promises);

            result0 = (Dictionary <string, string>)CallContext.LogicalGetData(name1);
            Assert.AreSame(dict, result0, "Same object LCC.GetData-Task.Run-Get");
            Assert.AreEqual(data1, result0[name1], "LCC.GetData-Main-Final");
        }
コード例 #4
0
        public void Interning_SiloAddress_Serialization()
        {
            SiloAddress a1 = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 1111), 12345);

            // Round-trip through Serializer
            SiloAddress a3 = (SiloAddress)SerializationManager.RoundTripSerializationForTesting(a1);

            Assert.AreEqual(a1, a3, "Should be equal SiloAddress's");
            Assert.AreSame(a1, a3, "Should be same / intern'ed SiloAddress object");
        }
コード例 #5
0
        public void ID_Interning_string_equals()
        {
            Interner <string, string> interner = new Interner <string, string>();
            const string str = "1";
            string       r1  = interner.FindOrCreate("1", () => str);
            string       r2  = interner.FindOrCreate("1", () => null); // Should always be found

            Assert.AreEqual(r1, r2, "1: Objects should be equal");
            Assert.AreSame(r1, r2, "2: Objects should be same / intern'ed");

            // Round-trip through Serializer
            string r3 = (string)SerializationManager.RoundTripSerializationForTesting(r1);

            Assert.AreEqual(r1, r3, "3: Should be equal");
            Assert.AreEqual(r2, r3, "4: Should be equal");
        }
コード例 #6
0
        public void ID_Interning_GrainID()
        {
            Guid    guid = new Guid();
            GrainId gid1 = GrainId.FromParsableString(guid.ToString("B"));
            GrainId gid2 = GrainId.FromParsableString(guid.ToString("N"));

            Assert.AreEqual(gid1, gid2, "Should be equal GrainId's");
            Assert.AreSame(gid1, gid2, "Should be same / intern'ed GrainId object");

            // Round-trip through Serializer
            GrainId gid3 = (GrainId)SerializationManager.RoundTripSerializationForTesting(gid1);

            Assert.AreEqual(gid1, gid3, "Should be equal GrainId's");
            Assert.AreEqual(gid2, gid3, "Should be equal GrainId's");
            Assert.AreSame(gid1, gid3, "Should be same / intern'ed GrainId object");
            Assert.AreSame(gid2, gid3, "Should be same / intern'ed GrainId object");
        }
コード例 #7
0
        public void ID_IsSystem()
        {
            GrainId testGrain = Constants.DirectoryServiceId;

            output.WriteLine("Testing GrainID " + testGrain);
            Assert.IsTrue(testGrain.IsSystemTarget, "System grain ID is not flagged as a system ID");

            GrainId sGrain = (GrainId)SerializationManager.DeepCopy(testGrain);

            output.WriteLine("Testing GrainID " + sGrain);
            Assert.IsTrue(sGrain.IsSystemTarget, "String round-trip grain ID is not flagged as a system ID");
            Assert.AreEqual(testGrain, sGrain, "Should be equivalent GrainId object");
            Assert.AreSame(testGrain, sGrain, "Should be same / intern'ed GrainId object");

            ActivationId testActivation = ActivationId.GetSystemActivation(testGrain, SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 2456), 0));

            output.WriteLine("Testing ActivationID " + testActivation);
            Assert.IsTrue(testActivation.IsSystem, "System activation ID is not flagged as a system ID");
        }
コード例 #8
0
 public static void Same(object expected, object actual)
 {
     FrameworkAssert.AreSame(expected, actual);
 }
コード例 #9
0
 public static void AreSame(object expected, object actual, string message)
 {
     MSAssert.AreSame(expected, actual, message);
 }
コード例 #10
0
 public static void AreSame(object expected, object actual)
 {
     MSAssert.AreSame(expected, actual, string.Format("Expected\n{0}\nto be the same as:\n{1}", expected, actual));
 }
コード例 #11
0
ファイル: NUnitAdapter.cs プロジェクト: villiOS/NLog
 public static void AreSame(object expected, object actual)
 {
     MSAssert.AreSame(expected, actual);
 }
コード例 #12
0
ファイル: NUnitAdapter.cs プロジェクト: ozgurtt/NLog
 public static void AreSame(object o1, object o2, string message)
 {
     MSAssert.AreSame(o1, o2, message);
 }
コード例 #13
0
ファイル: NUnitAdapter.cs プロジェクト: ozgurtt/NLog
 public static void AreSame(object o1, object o2)
 {
     MSAssert.AreSame(o1, o2);
 }