Пример #1
0
    public void SimpleInterfaceCopy()
    {
        // ARRAGE
        BClass original = new BClass()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        IBClass copy = interfaceCopier.Copy(original);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(IBClass)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(original, copy);
        Assert.IsInstanceOf <BClass>(original);
        Assert.IsInstanceOf <BClass>(copy);
        Assert.AreSame(original.Name, copy.Name);
    }
Пример #2
0
    public void IgnoreMember()
    {
        // ARRAGE
        BClassWithIgnoreMember original = new BClassWithIgnoreMember()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        original.KeepReference = original;

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        BClassWithIgnoreMember copy = instanceIgnoreMemberCopier.Copy(original, settings);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(BClassWithIgnoreMember)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(original, copy);
        Assert.AreEqual(default(int), copy.id);
        Assert.AreEqual(copy.Age, original.Age);
        Assert.AreSame(default(string), copy.Name);
        Assert.AreSame(copy.KeepReference, default(BClassWithIgnoreMember));
    }
Пример #3
0
    public void KeepSameReference()
    {
        // ARRAGE
        BClassWithKeepReference original = new BClassWithKeepReference()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        original.KeepReference = original;

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        BClassWithKeepReference copy = instanceKeepRefCopier.Copy(original, settings);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(BClassWithKeepReference)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(original, copy);
        Assert.AreEqual(original.id, copy.id);
        Assert.AreEqual(original.Age, copy.Age);
        Assert.AreSame(original.Name, copy.Name);
        Assert.AreSame(original.KeepReference, copy.KeepReference);
    }
Пример #4
0
    public void CopyWithRecursion()
    {
        // ARRAGE
        BClassWithRecursion original = new BClassWithRecursion()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        original.Recursion = original;

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        BClassWithRecursion copy = instanceRecursionCopier.Copy(original);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(BClassWithRecursion)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(original, copy);
        Assert.AreNotSame(original.Recursion, copy.Recursion);

        Assert.AreSame(original, original.Recursion);
        Assert.AreSame(copy, copy.Recursion);

        Assert.AreEqual(original.id, copy.id);
        Assert.AreEqual(original.Age, copy.Age);
        Assert.AreSame(original.Name, copy.Name);
    }
Пример #5
0
    public void DictionaryCopy()
    {
        // ARRAGE
        BClass c1 = new BClass()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        BClass c2 = new BClass()
        {
            id   = 420,
            Age  = 33,
            Name = "Ketsueki"
        };

        Dictionary <int, BClass> dict = new Dictionary <int, BClass>()
        {
            { 13, c1 },
            { 666, c2 }
        };

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        Dictionary <int, BClass> copy = dictCopier.Copy(dict);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(Dictionary<int, BClass>)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(dict, copy);
        Assert.AreEqual(dict.Count, copy.Count);

        if (dict.Count != copy.Count)
        {
            return;
        }

        for (int i = 0; i < copy.Count; i++)
        {
            var k1 = dict.Keys.ElementAt(i);
            var k2 = copy.Keys.ElementAt(i);

            var v1 = dict.Values.ElementAt(i);
            var v2 = copy.Values.ElementAt(i);

            Assert.AreEqual(k1, k2);
            Assert.AreNotSame(v1, v2);
        }
    }
Пример #6
0
    public void ListCopy()
    {
        // ARRAGE
        BClass c1 = new BClass()
        {
            id   = 69,
            Age  = 23,
            Name = "Bloodthirst"
        };

        BClass c2 = new BClass()
        {
            id   = 420,
            Age  = 33,
            Name = "Ketsueki"
        };

        List <BClass> lst = new List <BClass>()
        {
            c1,
            c2
        };

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        List <BClass> copy = listCopier.Copy(lst);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(List<BClass>)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(lst, copy);
        Assert.AreEqual(lst.Count, copy.Count);

        if (lst.Count != copy.Count)
        {
            return;
        }

        for (int i = 0; i < lst.Count; i++)
        {
            Assert.AreNotSame(lst[i], copy[i]);
        }

        CollectionAssert.AreNotEqual(lst, copy);
        CollectionAssert.IsNotSubsetOf(lst, copy);
    }
Пример #7
0
    public void CopyWithPrivateMembers()
    {
        // ARRAGE
        BClassPrivate original = new BClassPrivate(13, 23, "Bloodthirst");

        Stopwatch profile = new Stopwatch();

        // ACT
        profile.Start();

        BClassPrivate copy = instancePrivateCopier.Copy(original);

        profile.Stop();

        TestContext.Out.WriteLine($"Time for copying {nameof(BClassPrivate)} : { profile.ElapsedTicks } ticks = { profile.ElapsedMilliseconds } ms ");

        // ASSERT
        Assert.AreNotSame(original, copy);
        Assert.AreEqual(original.Id, copy.Id);
        Assert.AreEqual(original.Age, copy.Age);
        Assert.AreSame(original.Name, copy.Name);
    }