public void ShouldGetNewItemVersion()
        {
            // arrange
            var itemId = ID.NewID;
            var dbitem = new DbItem("home")
            {
                { "Title", "Hello!" }
            };

            this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

            var originalItem       = ItemHelper.CreateInstance(this.database, itemId);
            var itemWithNewVersion = ItemHelper.CreateInstance(this.database, itemId);

            this.dataStorage.GetSitecoreItem(itemId, Language.Parse("en"), Version.Parse(2)).Returns(itemWithNewVersion);

            var command = new OpenAddVersionCommand();

            command.Initialize(originalItem);
            command.Initialize(this.dataStorage);

            // act
            var result = command.DoExecute();

            // assert
            result.Should().BeSameAs(itemWithNewVersion);
        }
        public void ShouldAddVersionToFakeDbFieldsUsingItemLanguage()
        {
            // arrange
            var itemId = ID.NewID;
            var dbitem = new DbItem("item")
            {
                Fields = { new DbField("Title")
                           {
                               { "en", "Hello!" }, { "da", "Hej!" }
                           } }
            };

            this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

            var item = ItemHelper.CreateInstance(this.database, itemId);

            var command = new OpenAddVersionCommand();

            command.Initialize(item);
            command.Initialize(this.dataStorage);

            // act
            command.DoExecute();

            // assert
            dbitem.Fields.Single().Values["en"][1].Should().Be("Hello!");
            dbitem.Fields.Single().Values["en"][2].Should().Be("Hello!");
            dbitem.Fields.Single().Values["da"][1].Should().Be("Hej!");
            dbitem.Fields.Single().Values["da"].ContainsKey(2).Should().BeFalse();
        }
    public void ShouldCreateInstance()
    {
      // arrange
      var command = new OpenAddVersionCommand();
      command.Initialize(this.dataStorage);

      // act & assert
      command.CreateInstance().Should().BeOfType<AddVersionCommand>();
    }
        public void ShouldCreateInstance()
        {
            // arrange
            var command = new OpenAddVersionCommand();

            command.Initialize(this.dataStorage);

            // act & assert
            command.CreateInstance().Should().BeOfType <AddVersionCommand>();
        }
    public void ShouldCreateInstance()
    {
      // arrange
      var createdCommand = Substitute.For<AddVersionCommand>();
      this.innerCommand.CreateInstance<Sitecore.Data.Engines.DataCommands.AddVersionCommand, AddVersionCommand>().Returns(createdCommand);

      var command = new OpenAddVersionCommand();
      command.Initialize(this.innerCommand);

      // act & assert
      command.CreateInstance().Should().Be(createdCommand);
    }
    public void ShouldAddVersionIfNoVersionExistsInSpecificLanguage()
    {
      // arrange
      var itemId = ID.NewID;
      var dbitem = new DbItem("item") { Fields = { new DbField("Title") } };
      this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

      var item = ItemHelper.CreateInstance(this.database, itemId);

      var command = new OpenAddVersionCommand();
      command.Initialize(item);
      command.Initialize(this.dataStorage);

      // act
      command.DoExecute();

      // assert
      dbitem.Fields.Single().Values["en"][1].Should().BeEmpty();
    }
        public void ShouldIncreaseFakeItemVersionCount()
        {
            // arrange
            var itemId = ID.NewID;
            var dbitem = new DbItem("item");

            this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

            var item = ItemHelper.CreateInstance(this.database, itemId);

            var command = new OpenAddVersionCommand();

            command.Initialize(item);
            command.Initialize(this.dataStorage);

            // act
            command.DoExecute();

            // assert
            dbitem.VersionsCount["en"].Should().Be(2);
        }
    public void ShouldGetNewItemVersion()
    {
      // arrange
      var itemId = ID.NewID;
      var dbitem = new DbItem("home") { { "Title", "Hello!" } };
      this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

      var originalItem = ItemHelper.CreateInstance(this.database, itemId);
      var itemWithNewVersion = ItemHelper.CreateInstance(this.database, itemId);
      this.dataStorage.GetSitecoreItem(itemId, Language.Parse("en"), Version.Parse(2)).Returns(itemWithNewVersion);

      var command = new OpenAddVersionCommand();
      command.Initialize(originalItem);
      command.Initialize(this.dataStorage);

      // act
      var result = command.DoExecute();

      // assert
      result.Should().BeSameAs(itemWithNewVersion);
    }
    public void ShouldAddVersionToFakeDbFieldsUsingItemLanguage()
    {
      // arrange
      var itemId = ID.NewID;
      var dbitem = new DbItem("item") { Fields = { new DbField("Title") { { "en", "Hello!" }, { "da", "Hej!" } } } };
      this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

      var item = ItemHelper.CreateInstance(this.database, itemId);

      var command = new OpenAddVersionCommand();
      command.Initialize(item);
      command.Initialize(this.dataStorage);

      // act
      command.DoExecute();

      // assert
      dbitem.Fields.Single().Values["en"][1].Should().Be("Hello!");
      dbitem.Fields.Single().Values["en"][2].Should().Be("Hello!");
      dbitem.Fields.Single().Values["da"][1].Should().Be("Hej!");
      dbitem.Fields.Single().Values["da"].ContainsKey(2).Should().BeFalse();
    }
        public void ShouldAddVersionIfNoVersionExistsInSpecificLanguage()
        {
            // arrange
            var itemId = ID.NewID;
            var dbitem = new DbItem("item")
            {
                Fields = { new DbField("Title") }
            };

            this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

            var item = ItemHelper.CreateInstance(this.database, itemId);

            var command = new OpenAddVersionCommand();

            command.Initialize(item);
            command.Initialize(this.dataStorage);

            // act
            command.DoExecute();

            // assert
            dbitem.Fields.Single().Values["en"][1].Should().BeEmpty();
        }
    public void ShouldIncreaseFakeItemVersionCount()
    {
      // arrange
      var itemId = ID.NewID;
      var dbitem = new DbItem("item");
      this.dataStorage.GetFakeItem(itemId).Returns(dbitem);

      var item = ItemHelper.CreateInstance(this.database, itemId);

      var command = new OpenAddVersionCommand();
      command.Initialize(item);
      command.Initialize(this.dataStorage);

      // act
      command.DoExecute();

      // assert
      dbitem.VersionsCount["en"].Should().Be(2);
    }