public void SaveRedisSource_Execute_GivenResourceDefinition_ShouldSave() { //----------------------Arrange---------------------- var mockResourceCatalog = new Mock <IResourceCatalog>(); var redisSourceDefination = new RedisSourceDefinition { Name = "redisSource", HostName = "testHost", Password = "******", AuthenticationType = AuthenticationType.Password }; mockResourceCatalog.Setup(o => o.SaveResource(It.IsAny <Guid>(), redisSourceDefination.SerializeToJsonStringBuilder(), string.Empty)); var sut = new SaveRedisSource(mockResourceCatalog.Object); //----------------------Act-------------------------- var result = sut.Execute(new Dictionary <string, StringBuilder> { { "RedisSource", redisSourceDefination.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 <RedisSource>(), It.IsAny <string>()), Times.Once); }
public void TestRedisSource_Execute_GivenResourceDefinition_ShouldTestNewSourceReturnResourceDefinitionMsg() { //---------------Set up test pack------------------- var dependency = new Depends(Depends.ContainerType.AnonymousRedis); var serializer = new Dev2JsonSerializer(); var source = new RedisSourceDefinition() { Id = Guid.Empty, Name = "Name", HostName = dependency.Container.IP, Port = dependency.Container.Port, AuthenticationType = Dev2.Runtime.ServiceModel.Data.AuthenticationType.Anonymous }; var testRedisSource = new TestRedisSource(); var values = new Dictionary <string, StringBuilder> { { "RedisSource", source.SerializeToJsonStringBuilder() } }; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var jsonResult = testRedisSource.Execute(values, null); var result = serializer.Deserialize <ExecuteMessage>(jsonResult); //---------------Test Result ----------------------- Assert.IsFalse(result.HasError, result.Message.ToString()); }
public void SaveRedisSource_Execute_GivenResourceDefination_GivenExising_ShouldReturnResourceDefinationMsg() { //---------------Set up test pack------------------- var serializer = new Dev2JsonSerializer(); var source = new RedisSourceDefinition() { Id = Guid.Empty, Name = "Name", HostName = "HostName", Port = "3679", AuthenticationType = AuthenticationType.Anonymous }; var compressedExecuteMessage = new CompressedExecuteMessage(); var serializeToJsonString = source.SerializeToJsonString(new DefaultSerializationBinder()); compressedExecuteMessage.SetMessage(serializeToJsonString); var values = new Dictionary <string, StringBuilder> { { "RedisSource", source.SerializeToJsonStringBuilder() } }; var catalog = new Mock <IResourceCatalog>(); var redisSource = new RedisSource(); catalog.Setup(resourceCatalog => resourceCatalog.GetResource(It.IsAny <Guid>(), source.Name)).Returns(redisSource); catalog.Setup(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), redisSource, It.IsAny <string>())); var saveRedisSource = new SaveRedisSource(catalog.Object); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var jsonResult = saveRedisSource.Execute(values, null); var result = serializer.Deserialize <ExecuteMessage>(jsonResult); //---------------Test Result ----------------------- Assert.IsFalse(result.HasError); catalog.Verify(resourceCatalog => resourceCatalog.SaveResource(It.IsAny <Guid>(), redisSource, It.IsAny <string>())); }