Exemplo n.º 1
0
    public void Can_Deep_Clone()
    {
        var dtd = _builder
                  .WithId(3123)
                  .Build();

        var clone = (DataType)dtd.DeepClone();

        Assert.AreNotSame(clone, dtd);
        Assert.AreEqual(clone, dtd);
        Assert.AreEqual(clone.CreateDate, dtd.CreateDate);
        Assert.AreEqual(clone.CreatorId, dtd.CreatorId);
        Assert.AreEqual(clone.DatabaseType, dtd.DatabaseType);
        Assert.AreEqual(clone.Id, dtd.Id);
        Assert.AreEqual(clone.Key, dtd.Key);
        Assert.AreEqual(clone.Level, dtd.Level);
        Assert.AreEqual(clone.Name, dtd.Name);
        Assert.AreEqual(clone.ParentId, dtd.ParentId);
        Assert.AreEqual(clone.Path, dtd.Path);
        Assert.AreEqual(clone.SortOrder, dtd.SortOrder);
        Assert.AreEqual(clone.Trashed, dtd.Trashed);
        Assert.AreEqual(clone.UpdateDate, dtd.UpdateDate);

        // This double verifies by reflection
        var allProps = clone.GetType().GetProperties();

        foreach (var propertyInfo in allProps)
        {
            Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(dtd, null));
        }
    }
        public void Is_Built_Correctly()
        {
            // Arrange
            const int    testId          = 3123;
            const string testEditorAlias = "testAlias";
            const string testEditorName  = "Test Name";

            var builder = new DataTypeBuilder();

            // Act
            DataType dataType = builder
                                .WithId(testId)
                                .AddEditor()
                                .WithAlias(testEditorAlias)
                                .WithName(testEditorName)
                                .WithDefaultConfiguration(new Dictionary <string, object>
            {
                { "value1", "value1" },
                { "value2", "value2" },
            })
                                .Done()
                                .Build();

            // Assert
            Assert.AreEqual(testId, dataType.Id);
            Assert.AreEqual(testEditorAlias, dataType.Editor.Alias);
            Assert.AreEqual(testEditorName, dataType.Editor.Name);
            Assert.AreEqual(2, dataType.Editor.DefaultConfiguration.Count);
            Assert.AreEqual("value1", dataType.Editor.DefaultConfiguration["value1"]);
        }