Пример #1
0
        public void WhenGetItemIsCalled_ThenTheReturnedItem_IsCorrect()
        {
            //Assign
            const long id = 1L;

            ContentType.AddPropity("Test", "string");
            var item = Sut.CreateItem(ContentType);

            item.Id = id;

            const string propityValue = "NotDefaultValue";
            var          fi           = new FurnaceItemInformation <long>()
            {
                Id = id
            };
            var returnJson = new Stub
            {
                FurnaceItemInformation = fi,
                Test = propityValue
            }.BuildSerialisedString();

            var key = RedisBackedFurnaceItems.CreateItemKey(id, ContentType);

            Client.Hashes[key][SiteConfiguration.DefaultSiteCulture.Name].Returns(returnJson);

            //Act
            var result = Sut.GetItem(id, ContentType);

            //Assert
            Assert.That(result.Id, Is.EqualTo(id));
            Assert.That(result["Test"], Is.EqualTo(propityValue));
            Assert.That(result.ContentType.Name == ContentTypeName);
        }
Пример #2
0
        public void WhenCreateItemIsCalled_WithNoName_ThenInvalidPropertyException_IsThrown()
        {
            //Assign
            const string propertyTypeOne = "string";

            ContentType.AddPropity(type: propertyTypeOne);

            const string propertyTypeTwo = "string";

            ContentType.AddPropity(type: propertyTypeTwo);

            //Act
            var exception = Assert.Throws <FurnaceItems.InvalidContentTypeException>(() => Sut.CreateItem(ContentType));

            //Assert
            var reasons = exception.InvalidReasons.ToList();

            var invalidReasonOne = string.Format(FurnaceItems.InvalidContentTypeException.PropertyHasNoName, propertyTypeOne);

            Assert.That(reasons[0], Is.EqualTo(invalidReasonOne));

            var invalidReasonTwo = string.Format(FurnaceItems.InvalidContentTypeException.PropertyHasNoName, propertyTypeTwo);

            Assert.That(reasons[1], Is.EqualTo(invalidReasonTwo));
        }
Пример #3
0
        public void AndHasDefaultValue_WhenCreateItemIsCalled_ThenValue_IsDefault()
        {
            //Assign
            ContentType.AddPropity(PropertyName, PropertyType, DefaultValue);

            //Act
            var item = Sut.CreateItem(ContentType);

            //Assert
            Assert.That(item[PropertyName], Is.EqualTo(DefaultValue));
        }
Пример #4
0
        public void AndNoDefaultValue_WhenCreateItemIsCalled_ThenValue_IsNull()
        {
            //Assign
            ContentType.AddPropity(PropertyName, PropertyType);

            //Act
            var item = Sut.CreateItem(ContentType);

            //Assert
            Assert.That(item[PropertyName], Is.Null);
        }
Пример #5
0
        public void NoItemWithId_WhenGetItemIsCalled_ThenNullReturned()
        {
            //Assign
            const long Id = 1L;

            ContentType.AddPropity(PropertyName, PropertyType);

            //Act
            var result = Sut.GetItem(Id, ContentType);

            Assert.That(result, Is.Null);
        }
Пример #6
0
        public void WhenGetItemIsCalled_ThenCorrectKey_IsUsed()
        {
            //Assign
            CultureInfo = CultureInfo.GetCultureInfo("ja-JP");
            ContentType.AddPropity("SomeName", "string");

            //Act
            Sut.GetItem(Id, ContentType, CultureInfo);

            //Assert
            Spy.AssertWhenGetItemIsCalled_ThenCorrectKey_IsUsed(this);
        }
Пример #7
0
        public void GivenNoItemWithID_WhenGetItemIsCalled_ThenNullReturned()
        {
            //Assign
            const long id = 1L;

            ContentType.AddPropity("SomeName", "SomeType");

            //Act
            var result = Sut.GetItem(id, ContentType);

            //Assert
            Assert.That(result, Is.Null);
        }
Пример #8
0
        public void AndNoName_WhenCreateItemIsCalled_ThenInvalidPropertyException_IsThrown()
        {
            //Assign
            ContentType.AddPropity(type: PropertyType);

            //Act
            var exception = Assert.Throws <FurnaceItems.InvalidContentTypeException>(() => Sut.CreateItem(ContentType));

            //Assert
            var invalidReason = string.Format(FurnaceItems.InvalidContentTypeException.PropertyHasNoName, PropertyType);

            Assert.That(exception.InvalidReasons.First(), Is.EqualTo(invalidReason));
        }