public void GetFieldThrowsIfNoFieldIdFound(DbFieldCollection sut, ID missingFieldId)
    {
      var expectedMessage = string.Format("The given field \"{0}\" is not present in the item.", missingFieldId);

      Assert.Throws<InvalidOperationException>(() => sut[missingFieldId])
        .Message.Should().Be(expectedMessage);
    }
Ejemplo n.º 2
0
        public void GetFieldThrowsIfNoFieldIdFound(DbFieldCollection sut, ID missingFieldId)
        {
            var expectedMessage = string.Format("The given field \"{0}\" is not present in the item.", missingFieldId);

            Assert.Throws <InvalidOperationException>(() => sut[missingFieldId])
            .Message.Should().Be(expectedMessage);
        }
Ejemplo n.º 3
0
        public void TryGetValueReturnsFalseAndEmptyStringIfNoValueFound(DbFieldCollection sut, ID fieldId)
        {
            string value;

            sut.TryGetValue(fieldId, out value).Should().BeFalse();
            value.Should().BeEmpty();
        }
Ejemplo n.º 4
0
        public void ResetFieldById(DbFieldCollection sut, [Frozen] ID id, DbField originalField, DbField newField)
        {
            sut[id] = originalField;
            sut[id] = newField;

            sut[id].Should().BeSameAs(newField);
        }
Ejemplo n.º 5
0
        public void SutReturnsFields(DbFieldCollection sut, DbField field1, DbField field2)
        {
            sut.Add(field1);
            sut.Add(field2);

            sut.ShouldAllBeEquivalentTo(new[] { field1, field2 });
        }
    public void ResetFieldById(DbFieldCollection sut, [Frozen] ID id, DbField originalField, DbField newField)
    {
      sut[id] = originalField;
      sut[id] = newField;

      sut[id].Should().BeSameAs(newField);
    }
    public void ShouldAddDbField()
    {
      // arrange
      var collection = new DbFieldCollection { new DbField("Title") };

      // act & assert
      collection.Count().Should().Be(1);
    }
Ejemplo n.º 8
0
    public DbTemplate(string name, ID id, DbFieldCollection fields)
    {
      this.Name = name;
      this.ID = id;

      this.Fields = fields;
      this.StandardValues = new DbFieldCollection();
    }
        public void ShouldReturnFalseIfNoField()
        {
            // arrange
            var collection = new DbFieldCollection();

            // act & assert
            collection.ContainsKey(ID.NewID).Should().BeFalse();
        }
Ejemplo n.º 10
0
        public void TryGetValueReturnsTrueAndValue(DbFieldCollection sut, ID fieldId, string expected)
        {
            sut.Add(fieldId, expected);

            string value;

            sut.TryGetValue(fieldId, out value).Should().BeTrue();
            value.Should().Be(expected);
        }
        public void ShouldAddDbField()
        {
            // arrange
            var collection = new DbFieldCollection {
                new DbField("Title")
            };

            // act & assert
            collection.Count().Should().Be(1);
        }
    public void ShouldGetFieldById()
    {
      // arrange
      var id = ID.NewID;
      var field = new DbField("Title") { ID = id };
      var collection = new DbFieldCollection { field };

      // act & assert
      collection[id].ShouldBeEquivalentTo(field);
    }
        public void ShouldThrowExceptionIfNoFieldIdPresent()
        {
            // arrange
            var collection      = new DbFieldCollection();
            var missingFieldId  = ID.NewID;
            var expectedMessage = string.Format("The given field \"{0}\" is not present in the item.", missingFieldId);

            // act & assert
            Assert.Throws <InvalidOperationException>(() => collection[missingFieldId])
            .Message.Should().Be(expectedMessage);
        }
    public void ShouldThrowExceptionIfNoFieldIdPresent()
    {
      // arrange
      var collection = new DbFieldCollection();
      var missingFieldId = ID.NewID;
      var expectedMessage = string.Format("The given field \"{0}\" is not present in the item.", missingFieldId);

      // act & assert
      Assert.Throws<InvalidOperationException>(() => collection[missingFieldId])
        .Message.Should().Be(expectedMessage);
    }
        public void ShouldReturnTrueIfContainsField()
        {
            // arrange
            var fieldId    = ID.NewID;
            var collection = new DbFieldCollection {
                new DbField(fieldId)
            };

            // act & assert
            collection.ContainsKey(fieldId).Should().BeTrue();
        }
        public void ShouldGetValues()
        {
            // arrange
            var field1     = new DbField("field1");
            var field2     = new DbField("field2");
            var collection = new DbFieldCollection {
                field1, field2
            };

            // act & assert
            collection.ShouldAllBeEquivalentTo(new[] { field1, field2 });
        }
        public void ShouldGetFieldById()
        {
            // arrange
            var id         = ID.NewID;
            var field      = new DbField("Title", id);
            var collection = new DbFieldCollection {
                field
            };

            // act & assert
            collection[id].ShouldBeEquivalentTo(field);
        }
    public void ShouldAddFieldByNameAndValue()
    {
      // arrange & act
      var collection = new DbFieldCollection { { "field1", "value1" }, { "field2", "value2" } };

      // assert
      collection.ElementAt(0).Name.Should().Be("field1");
      collection.ElementAt(0).ID.Should().NotBeNull();
      collection.ElementAt(0).Value.Should().Be("value1");

      collection.ElementAt(1).Name.Should().Be("field2");
      collection.ElementAt(1).ID.Should().NotBeNull();
      collection.ElementAt(1).Value.Should().Be("value2");
    }
    public void ShouldSetFieldById()
    {
      // arrange
      var id = ID.NewID;
      var originalField = new DbField("Title") { ID = id };
      var newField = new DbField("Title") { ID = id };

      var collection = new DbFieldCollection { originalField };

      // act
      collection[id] = newField;

      // assert
      collection[id].ShouldBeEquivalentTo(newField);
    }
        public void ShouldAddFieldByNameAndValue()
        {
            // arrange & act
            var collection = new DbFieldCollection {
                { "field1", "value1" }, { "field2", "value2" }
            };

            // assert
            collection.ElementAt(0).Name.Should().Be("field1");
            collection.ElementAt(0).ID.Should().NotBeNull();
            collection.ElementAt(0).Value.Should().Be("value1");

            collection.ElementAt(1).Name.Should().Be("field2");
            collection.ElementAt(1).ID.Should().NotBeNull();
            collection.ElementAt(1).Value.Should().Be("value2");
        }
        public void ShouldSetFieldById()
        {
            // arrange
            var id            = ID.NewID;
            var originalField = new DbField("Title", id);
            var newField      = new DbField("Title", id);

            var collection = new DbFieldCollection {
                originalField
            };

            // act
            collection[id] = newField;

            // assert
            collection[id].ShouldBeEquivalentTo(newField);
        }
Ejemplo n.º 22
0
 public void AddFieldByName(DbFieldCollection sut, string fieldName)
 {
     sut.Add(fieldName);
     sut.Single().Name.Should().Be(fieldName);
 }
 public void ContainsKeyIsFalseIfNotFound(DbFieldCollection sut, ID missingFieldId)
 {
   sut.ContainsKey(missingFieldId).Should().BeFalse();
 }
 public void AddFieldByNameGeneratesNewId(DbFieldCollection sut, string fieldName)
 {
   sut.Add(fieldName);
   sut.Single().ID.Should().NotBe(ID.Null);
 }
Ejemplo n.º 25
0
 public void ContainsKeyIsFalseIfNotFound(DbFieldCollection sut, ID missingFieldId)
 {
     sut.ContainsKey(missingFieldId).Should().BeFalse();
 }
    public void ShouldGetValues()
    {
      // arrange
      var field1 = new DbField("field1");
      var field2 = new DbField("field2");
      var collection = new DbFieldCollection { field1, field2 };

      // act & assert
      collection.ShouldAllBeEquivalentTo(new[] { field1, field2 });
    }
Ejemplo n.º 27
0
 public void SetFieldById(DbFieldCollection sut, [Frozen] ID id, DbField field)
 {
     sut[id] = field;
     sut[id].Should().BeSameAs(field);
 }
Ejemplo n.º 28
0
 public void AddFieldByNameAndValue(DbFieldCollection sut, string fieldName, string value)
 {
     sut.Add(fieldName, value);
     sut.Single().Value.Should().Be(value);
 }
 public void GetFieldById(DbFieldCollection sut, DbField field)
 {
   sut.Add(field);
   sut[field.ID].ShouldBeEquivalentTo(field);
 }
Ejemplo n.º 30
0
    private static void MapFields(DbFieldCollection source, DbItem target)
    {
      foreach (var field in source)
      {
        var oldField = target.Fields.InnerFields.Values.SingleOrDefault(v => v.Name == field.Name);
        if (oldField == null)
        {
          continue;
        }

        target.Fields.InnerFields.Remove(oldField.ID);

        var renewedField = oldField;
        renewedField.ID = field.ID;
        target.Fields.InnerFields.Add(field.ID, renewedField);
      }
    }
 public void SetFieldById(DbFieldCollection sut, [Frozen] ID id, DbField field)
 {
   sut[id] = field;
   sut[id].Should().BeSameAs(field);
 }
    public void TryGetValueReturnsTrueAndValue(DbFieldCollection sut, ID fieldId, string expected)
    {
      sut.Add(fieldId, expected);

      string value;
      sut.TryGetValue(fieldId, out value).Should().BeTrue();
      value.Should().Be(expected);
    }
 public void TryGetValueReturnsFalseAndEmptyStringIfNoValueFound(DbFieldCollection sut, ID fieldId)
 {
   string value;
   sut.TryGetValue(fieldId, out value).Should().BeFalse();
   value.Should().BeEmpty();
 }
    public void SutReturnsFields(DbFieldCollection sut, DbField field1, DbField field2)
    {
      sut.Add(field1);
      sut.Add(field2);

      sut.ShouldAllBeEquivalentTo(new[] { field1, field2 });
    }
Ejemplo n.º 35
0
 public void AddFieldByNameGeneratesNewId(DbFieldCollection sut, string fieldName)
 {
     sut.Add(fieldName);
     sut.Single().ID.Should().NotBe(ID.Null);
 }
 public void AddFieldByName(DbFieldCollection sut, string fieldName)
 {
   sut.Add(fieldName);
   sut.Single().Name.Should().Be(fieldName);
 }
Ejemplo n.º 37
0
 public void AddFieldByNameSetsEmptyValue(DbFieldCollection sut, string fieldName)
 {
     sut.Add(fieldName);
     sut.Single().Value.Should().BeEmpty();
 }
 public void AddFieldByNameAndValue(DbFieldCollection sut, string fieldName, string value)
 {
   sut.Add(fieldName, value);
   sut.Single().Value.Should().Be(value);
 }
Ejemplo n.º 39
0
 public void GetFieldById(DbFieldCollection sut, DbField field)
 {
     sut.Add(field);
     sut[field.ID].ShouldBeEquivalentTo(field);
 }
Ejemplo n.º 40
0
 public void SutReturnsEnumerator(DbFieldCollection sut)
 {
     ((IEnumerable)sut).GetEnumerator().Should().NotBeNull();
 }
 public void AddFieldByNameSetsEmptyValue(DbFieldCollection sut, string fieldName)
 {
   sut.Add(fieldName);
   sut.Single().Value.Should().BeEmpty();
 }
 public void SutReturnsEnumerator(DbFieldCollection sut)
 {
   ((IEnumerable)sut).GetEnumerator().Should().NotBeNull();
 }
Ejemplo n.º 43
0
 public void ContainsFieldIsTrueIfExists(DbFieldCollection sut, DbField field)
 {
     sut.Add(field);
     sut.ContainsKey(field.ID).Should().BeTrue();
 }
    public void ShouldReturnTrueIfContainsField()
    {
      // arrange
      var fieldId = ID.NewID;
      var collection = new DbFieldCollection { new DbField(fieldId) };

      // act & assert
      collection.ContainsKey(fieldId).Should().BeTrue();
    }
    public void ShouldReturnFalseIfNoField()
    {
      // arrange
      var collection = new DbFieldCollection();

      // act & assert
      collection.ContainsKey(ID.NewID).Should().BeFalse();
    }
Ejemplo n.º 46
0
 public void AddField(DbFieldCollection sut, DbField field)
 {
     sut.Add(field);
     sut.Count().Should().Be(1);
 }
 public void AddField(DbFieldCollection sut, DbField field)
 {
   sut.Add(field);
   sut.Count().Should().Be(1);
 }
 public void ContainsFieldIsTrueIfExists(DbFieldCollection sut, DbField field)
 {
   sut.Add(field);
   sut.ContainsKey(field.ID).Should().BeTrue();
 }
Ejemplo n.º 49
0
 internal DbTemplate(string name, ID id, ID templateId)
   : base(name, ID.IsNullOrEmpty(id) ? ID.NewID : id, templateId)
 {
   this.StandardValues = new DbFieldCollection();
   this.ParentID = ItemIDs.TemplateRoot;
 }
Ejemplo n.º 50
0
    protected virtual void CreateTemplate(DbItem item)
    {
      var isResolved = this.ResolveTemplate(item);
      if (isResolved)
      {
        return;
      }

      if (!ID.IsNullOrEmpty(item.TemplateID) && this.DataStorage.GetFakeTemplate(item.TemplateID) != null)
      {
        return;
      }

      if (item.TemplateID == ID.Null)
      {
        item.TemplateID = ID.NewID;
      }

      var fields = new DbFieldCollection();
      foreach (var itemField in item.Fields)
      {
        var templatefield = new DbField(itemField.Name) { ID = itemField.ID };
        fields.Add(templatefield);
      }

      var template = new DbTemplate(item.Name, item.TemplateID, fields);

      this.Add(template);
    }