コード例 #1
0
        public void SaveElasticsearchSource_Execute_GivenResourceDefination_ShouldSaveNewSourceReturnResourceDefinationMsg()
        {
            //---------------Set up test pack-------------------
            var serializer = new Dev2JsonSerializer();
            var source     = new ElasticsearchSourceDefinition()
            {
                Id                 = Guid.Empty,
                Name               = "Name",
                HostName           = "HostName",
                Port               = "3679",
                AuthenticationType = AuthenticationType.Anonymous,
                SearchIndex        = "warewolflogs"
            };
            var compressedExecuteMessage = new CompressedExecuteMessage();
            var serializeToJsonString    = source.SerializeToJsonString(new DefaultSerializationBinder());

            compressedExecuteMessage.SetMessage(serializeToJsonString);
            var values = new Dictionary <string, StringBuilder>
            {
                { "ElasticsearchSource", source.SerializeToJsonStringBuilder() }
            };
            var catalog = new Mock <IResourceCatalog>();

            catalog.Setup(resourceCatalog => resourceCatalog.GetResource(It.IsAny <Guid>(), source.Name));
            catalog.Setup(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), It.IsAny <IResource>(), It.IsAny <string>()));
            var elasticsearchSource = new SaveElasticsearchSource(catalog.Object);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var jsonResult = elasticsearchSource.Execute(values, null);
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            //---------------Test Result -----------------------
            Assert.IsFalse(result.HasError);
            catalog.Verify(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), It.IsAny <IResource>(), It.IsAny <string>()));
        }
コード例 #2
0
        public void SaveElasticsearchSource_GivenResourceDefinition_ShouldSave()
        {
            //----------------------Arrange----------------------
            var mockResourceCatalog = new Mock <IResourceCatalog>();

            var elasticsearchSourceDefinition = new ElasticsearchSourceDefinition()
            {
                Name               = "ElasticsearchSource",
                HostName           = "testHost",
                Password           = "******",
                AuthenticationType = AuthenticationType.Password,
                SearchIndex        = "warewolflogs"
            };

            mockResourceCatalog.Setup(o => o.SaveResource(It.IsAny <Guid>(), elasticsearchSourceDefinition.SerializeToJsonStringBuilder(), string.Empty));

            var sut = new SaveElasticsearchSource(mockResourceCatalog.Object);
            //----------------------Act--------------------------
            var result = sut.Execute(new Dictionary <string, StringBuilder> {
                { "ElasticsearchSource", elasticsearchSourceDefinition.SerializeToJsonStringBuilder() }
            }, new Mock <IWorkspace>().Object);
            //----------------------Assert-----------------------
            var serializer = new Dev2JsonSerializer();

            Assert.IsFalse(serializer.Deserialize <ExecuteMessage>(result).HasError);
            mockResourceCatalog.Verify(o => o.SaveResource(It.IsAny <Guid>(), It.IsAny <ElasticsearchSource>(), It.IsAny <string>()), Times.Once);
        }
コード例 #3
0
        public void SaveElasticsearchSource_Execute_NullValues_ErrorResult()
        {
            //------------Setup for test--------------------------
            var elasticsearchSource = new SaveElasticsearchSource();
            var serializer          = new Dev2JsonSerializer();
            //------------Execute Test---------------------------
            var jsonResult = elasticsearchSource.Execute(null, null);
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            //------------Assert Results-------------------------
            Assert.IsTrue(result.HasError);
        }
コード例 #4
0
        public void SaveElasticsearchSource_Execute_ResourceIDNotPresent_ErrorResult()
        {
            //------------Setup for test--------------------------
            var values = new Dictionary <string, StringBuilder> {
                { "item", new StringBuilder() }
            };
            var elasticsearchSource = new SaveElasticsearchSource();
            var serializer          = new Dev2JsonSerializer();
            //------------Execute Test---------------------------
            var jsonResult = elasticsearchSource.Execute(values, null);
            var result     = serializer.Deserialize <ExecuteMessage>(jsonResult);

            //------------Assert Results-------------------------
            Assert.IsTrue(result.HasError);
        }