public void ShouldGetAllThePossibleItemVersions([Greedy] FakeDataProvider sut, ItemDefinition def, CallContext context)
        {
            // arrange
            var item = new DbItem("home", def.ID, def.TemplateID)
            {
                Fields =
                {
                    new DbField("Field 1")
                    {
                        { "en", 1, string.Empty }, { "en", 2, string.Empty }, { "da", 1, string.Empty }
                    },
                    new DbField("Field 2")
                    {
                        { "en", 1, string.Empty }, { "da", 1, string.Empty }, { "da", 2, string.Empty }
                    }
                }
            };

            sut.DataStorage.GetFakeItem(def.ID).Returns(item);

            // act
            var versions = sut.GetItemVersions(def, context);

            // assert
            versions.Count.Should().Be(4);
            versions[0].Language.Name.Should().Be("en");
            versions[0].Version.Number.Should().Be(1);
            versions[1].Language.Name.Should().Be("en");
            versions[1].Version.Number.Should().Be(2);
            versions[2].Language.Name.Should().Be("da");
            versions[2].Version.Number.Should().Be(1);
            versions[3].Language.Name.Should().Be("da");
            versions[3].Version.Number.Should().Be(2);
        }
        public void ShouldGetDefaultLanguage([Greedy] FakeDataProvider sut, CallContext context)
        {
            var langs = sut.GetLanguages(context);

            langs.Should().HaveCount(1);
            langs.First().Name.Should().Be("en");
        }
Example #3
0
        public void PutAddressReturnFakeObject()
        {
            var provider = new FakeDataProvider();
            var fo       = provider.ParseAddress(Address);

            Assert.AreEqual(fo.MinValue, 32);
        }
        public void TestObserverJobExecution_When_User_Was_Under_Attack_Gameplay_Returns_Attack()
        {
            var villageRepoMock = new Mock <IVillageRepository>();

            villageRepoMock.Setup(x => x.GetVillages(FakeDataProvider.TravianUserName))
            .Returns(Task.FromResult((IEnumerable <VillageModel>)FakeDataProvider.GetVillagesFromDatabase(true)));

            _serviceBuilder = _serviceBuilder
                              .WithService(villageRepoMock.Object);

            var observerJob = new ObserverJob(_serviceBuilder.Build());
            var context     = new Mock <IJobExecutionContext>();
            var jobDetail   = new Mock <IJobDetail>();
            var data        = new JobExecutionData
            {
                TravianUser = FakeDataProvider.GetUser(PlayerStatus.UNDER_ATTACK, true)
            };

            jobDetail.Setup(x => x.JobDataMap[AbstractJob.JobExecutionDataKey]).Returns(data);
            context.Setup(x => x.JobDetail).Returns(jobDetail.Object);
            Assert.DoesNotThrowAsync(async() => await observerJob.Execute(data));
            _logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Never);
            _cmdFactoryMock.Verify(x => x.GetQueueableCommand(nameof(PrepareToAttackCommand), It.IsAny <long>()), Times.Once);
            _travianUserRepoMock.Verify(x => x.ReplacePlayerDataVillages(It.IsAny <TravianUser>()), Times.Once);

            Assert.AreEqual(2, _reportMsgs.Count);
            Assert.IsTrue(_reportMsgs[1].Contains($"Village [test_village_under_attack] is under attack."));
            Assert.IsTrue(_reportMsgs[1].Contains(FakeDataProvider.NewAttackDateTime.ToDisplayStringApplyTimeZone("UTC+2")));

            Assert.AreEqual(1, _updates.Count);
            Assert.AreEqual(PlayerStatus.UNDER_ATTACK, _updates.First().PlayerData.Status);
        }
        public void ChangeTemplateThrowsIfNoDbItemFound([Greedy] FakeDataProvider sut, ItemDefinition def, TemplateChangeList changes)
        {
            Action action = () => sut.ChangeTemplate(def, changes, null);

            action.ShouldThrow <InvalidOperationException>()
            .WithMessage("Unable to change item template. The item '{0}' is not found.".FormatWith(def.ID));
        }
Example #6
0
 public void ShouldGetNullItemDefinitionIfNoItemFound(
     [Greedy] FakeDataProvider sut,
     ID itemId,
     CallContext context)
 {
     sut.GetItemDefinition(itemId, context).Should().BeNull();
 }
Example #7
0
        private void ReportButtonClick(object sender, EventArgs e)
        {
            var report             = new Report();
            var piluleDataProvider = new FakeDataProvider();
            var piluleData         = piluleDataProvider.GetData(null);

            var applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var piluleDataPath      = Path.Combine(applicationDataPath, "Pilule");

            if (!Directory.Exists(piluleDataPath))
            {
                Directory.CreateDirectory(piluleDataPath);
            }

            var reportPath = Path.Combine(piluleDataPath, "PiluleReport.frx");

            if (!File.Exists(reportPath))
            {
                report.Save(reportPath);
            }

            report.Load(reportPath);
            report.RegisterData(piluleData, "PD");

            if (this.DesignModeCheckBox.Checked)
            {
                report.Design(false);
            }
            else
            {
                report.Show(false);
            }
        }
Example #8
0
        public void ShouldResolvePath(string path, [Greedy] FakeDataProvider sut, DbItem item, CallContext context)
        {
            item.FullPath = "/sitecore/content/home";
            sut.DataStorage.GetFakeItems().Returns(new[] { item });

            sut.ResolvePath(path, context).Should().Be(item.ID);
        }
Example #9
0
 public void ShouldGetEmptyVersionsIfNoFakeItemFound(
     [Greedy] FakeDataProvider sut,
     ItemDefinition def,
     CallContext context)
 {
     sut.GetItemVersions(def, context).Should().BeEmpty();
 }
Example #10
0
        public void ShouldGetTemplatesWithDefaultDataSectionFromDataStorage([Greedy] FakeDataProvider sut, DbTemplate template)
        {
            sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
            var result = sut.GetTemplates(null).First();

            result.GetSection("Data").Should().NotBeNull();
        }
Example #11
0
        public void ShouldHaveStandardBaseTemplate([Greedy] FakeDataProvider sut, [NoAutoProperties] DbTemplate template)
        {
            sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
            var result = sut.GetTemplates(null).First();

            result.BaseIDs.Single().Should().Be(TemplateIDs.StandardTemplate);
        }
Example #12
0
 public void GetBlobStreamReturnsNullIfNoBlobStreamExists(
     [Greedy] FakeDataProvider sut,
     Guid blobId,
     CallContext context)
 {
     sut.GetBlobStream(blobId, context).Should().BeNull();
 }
Example #13
0
 public void GetChildIdsReturnsEmptyListIfNoItemFound(
     [Greedy] FakeDataProvider sut,
     ItemDefinition itemDefinition,
     CallContext context)
 {
     sut.GetChildIDs(itemDefinition, context).Should().BeEmpty();
 }
Example #14
0
        public void ShouldGetDefaultLanguage(
            [Greedy] FakeDataProvider sut,
            CallContext context)
        {
            var languages = sut.GetLanguages(context);

            languages.Should().BeEmpty();
        }
Example #15
0
        public void ShouldGetTemplateFields([Greedy] FakeDataProvider sut, DbTemplate template)
        {
            sut.DataStorage.GetFakeTemplates().Returns(new[] { template });
            template.Fields.Add("Title");
            var result = sut.GetTemplates(null).First();

            result.GetField("Title").Should().NotBeNull();
        }
Example #16
0
        public void GetParentIdThrowsIfItemDefinitionIsNull(
            [Greedy] FakeDataProvider sut,
            CallContext context)
        {
            Action action = () => sut.GetParentID(null, context);

            action.ShouldThrow <ArgumentNullException>().WithMessage("*itemDefinition");
        }
Example #17
0
 public void ShouldGetNullItemFieldsIfNoItemFound(
     [Greedy] FakeDataProvider sut,
     ItemDefinition def,
     VersionUri versionUri,
     CallContext context)
 {
     sut.GetItemFields(def, versionUri, context).Should().BeNull();
 }
Example #18
0
        public void GetPublishQueueReturnsEmptyIdListIfNoItemsAdded(
            [Greedy] FakeDataProvider sut,
            CallContext context)
        {
            var result = sut.GetPublishQueue(DateTime.MinValue, DateTime.MaxValue, context);

            result.Should().BeEmpty();
        }
Example #19
0
        public void ChangeTemplateThrowsIfNoTargetTemplateFound([Greedy] FakeDataProvider sut, ItemDefinition def, TemplateChangeList changes, DbItem item)
        {
            sut.DataStorage.GetFakeItem(def.ID).Returns(item);
            Action action = () => sut.ChangeTemplate(def, changes, null);

            action.ShouldThrow <InvalidOperationException>()
            .WithMessage("Unable to change item template. The target template is not found.");
        }
Example #20
0
        public void SaveItemThrowsIfItemChangesParameterIsNull(
            FakeDataProvider sut,
            ItemDefinition itemDefinition)
        {
            Action action = () => sut.SaveItem(itemDefinition, null, null);

            action.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("changes");
        }
Example #21
0
        public void CopyItemThrowsIfDestinationIsNull(
            FakeDataProvider sut,
            ItemDefinition source)
        {
            Action action = () => sut.CopyItem(source, null, null, ID.Null, null);

            action.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("destination");
        }
Example #22
0
 public void GetBlobStreamReturnsBlobStreamFromDataStorage(
     [Greedy] FakeDataProvider sut,
     Guid blobId,
     [Modest] MemoryStream stream,
     CallContext context)
 {
     sut.DataStorage.GetBlobStream(blobId).Returns(stream);
     sut.GetBlobStream(blobId, context).Should().BeSameAs(stream);
 }
 public void FetchData()
 {
     var provider = new FakeDataProvider<Career>();
     var stream = provider.FetchData(Url);
     Assert.IsNotNull(stream);
     Assert.AreNotEqual(0, stream.Length);
     var response = stream.CreateFromJsonStream<Career>();
     Assert.IsNotNull(response);
 }
Example #24
0
 public void SaveItemReturnsFalse(
     [Greedy] FakeDataProvider sut,
     ItemDefinition itemDefinition,
     ItemChanges changes,
     CallContext context)
 {
     // 'true' looks more correct here but numerous tests start failing then.
     sut.SaveItem(itemDefinition, changes, context).Should().BeFalse();
 }
Example #25
0
 public void RemoveVersionReturnsFalseIfNoVersionFound(
     [Greedy] FakeDataProvider sut,
     ItemDefinition itemDefinition,
     VersionUri version,
     DbItem item)
 {
     sut.DataStorage.GetFakeItem(itemDefinition.ID).Returns(item);
     sut.RemoveVersion(itemDefinition, version, null).Should().BeFalse();
 }
Example #26
0
 public void ShouldSetBlobStreamInDataStorage(
     [Greedy] FakeDataProvider sut,
     Guid blobId,
     [Modest] MemoryStream stream,
     CallContext context)
 {
     sut.SetBlobStream(stream, blobId, context);
     sut.DataStorage.Received().SetBlobStream(blobId, stream);
 }
Example #27
0
        public void GetParentIdReturnsNullIfNoItemFound(
            [Greedy] FakeDataProvider sut,
            ItemDefinition itemDefinition,
            CallContext context)
        {
            var result = sut.GetParentID(itemDefinition, context);

            result.Should().BeNull();
        }
Example #28
0
 public void AddToPublishQueueReturnsTrue(
     [Greedy] FakeDataProvider sut,
     ID itemId,
     string action,
     DateTime date,
     CallContext context)
 {
     sut.AddToPublishQueue(itemId, action, date, context).Should().BeTrue();
 }
Example #29
0
 public void StartProviderWithOneAddressGetTwoValues()
 {
     var provider = new FakeDataProvider();
     var config = new Dictionary<string, object>();
     config.Add("Addresses", new List<string> {Address});
     provider.DataRecievedEvent += OnDataReceivedEvent;
     provider.Initialize(config);
     Thread.Sleep(TimeSpan.FromSeconds(1));
     Assert.AreEqual(_valuesCount, 2);
 }
Example #30
0
        public void CopyItemThrowsIfCopyIdIsNull(
            FakeDataProvider sut,
            ItemDefinition source,
            ItemDefinition destination,
            string copyName)
        {
            Action action = () => sut.CopyItem(source, destination, copyName, null, null);

            action.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("copyId");
        }
Example #31
0
        public void RemoveVersionThrowsIfItemDefinitionNotFound(
            [Greedy] FakeDataProvider sut,
            ItemDefinition itemDefinition,
            VersionUri baseVersion)
        {
            Action action = () => sut.RemoveVersion(itemDefinition, baseVersion, null);

            action.ShouldThrow <InvalidOperationException>()
            .WithMessage("Unable to remove item version. The item '{0}' is not found.".FormatWith(itemDefinition.ID));
        }
Example #32
0
        public void MoveItemThrowsIfItemDefinitionNotFound(
            [Greedy] FakeDataProvider sut,
            ItemDefinition itemDefinition,
            ItemDefinition destination)
        {
            Action action = () => sut.MoveItem(itemDefinition, destination, null);

            action.ShouldThrow <InvalidOperationException>()
            .WithMessage("Unable to move item. The item '{0}' is not found.".FormatWith(itemDefinition.ID));
        }
Example #33
0
 public void PutAddressReturnFakeObject()
 {
     var provider = new FakeDataProvider();
     var fo = provider.ParseAddress(Address);
     Assert.AreEqual(fo.MinValue, 32);
 }