public ProjectRepositoryFixture() { RedisMapper.RegisterType <ProjectReadModel>(); RedisConnection = ConnectionMultiplexer.Connect("localhost"); DeleteTestDatabase(); SetupTestDatabase(); }
public void FromRedis_should_return_an_object_of_a_supported_type_without_a_collection() { RedisMapper.RegisterType <TestType1>(); var subject = new[] { new HashEntry("IntegerProperty", 1), new HashEntry("FloatProperty", 2.0f), new HashEntry("DoubleProperty", 3.0d), new HashEntry("BoolProperty", true), new HashEntry("StringProperty", "teszt"), new HashEntry("ByteArrayProperty", new byte[] { 0, 1, 2 }), new HashEntry("DateTimeProperty", new DateTime(2000, 1, 1, 12, 0, 0).ToString("O")), new HashEntry("GuidProperty", Guid.Empty.ToString()) }; var result = Assert.IsType <TestType1>(subject.FromRedis <TestType1>()); Assert.Equal(1, result.IntegerProperty); Assert.Equal(2.0f, result.FloatProperty); Assert.Equal(3.0d, result.DoubleProperty); Assert.Equal(true, result.BoolProperty); Assert.Equal("teszt", result.StringProperty); Assert.Equal(3, result.ByteArrayProperty.Length); Assert.Equal(0, result.ByteArrayProperty[0]); Assert.Equal(1, result.ByteArrayProperty[1]); Assert.Equal(2, result.ByteArrayProperty[2]); Assert.Equal(new DateTime(2000, 1, 1, 12, 0, 0), result.DateTimeProperty); Assert.Equal(Guid.Empty, result.GuidProperty); }
public void ToRedis_should_be_able_to_handle_list_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType2>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfStringsTestType2)], Has.One.Items); var subject = new CollectionOfStringsTestType2 { StringCollection = new List <string> { "item1", "item2", "item3", @"|item4" } }; var result = RedisMapper.MapToRedisValues(subject); Assert.That( result["StringCollection"], Is.EqualTo((RedisValue) $@"{ typeof(List<string>).AssemblyQualifiedName }||item1||item2||item3||\|item4")); }
public void FromRedis_should_return_an_object_of_a_supported_type_with_an_ICollection_of_Guids() { RedisMapper.RegisterType <CollectionOfGuidTestType1>(); var subject = new Dictionary <string, RedisValue> { { "GuidCollection", $@"{ typeof(List<Guid>).AssemblyQualifiedName }||00000000-0000-0000-0000-000000000000||11c43ee8-b9d3-4e51-b73f-bd9dda66e29c" } }; var result = RedisMapper.FromRedisValues <CollectionOfGuidTestType1>(subject); Assert.That(result.GuidCollection, Has.Exactly(2).Items); Assert.That( result.GuidCollection, Is.EquivalentTo(new[] { Guid.Empty, Guid.Parse("11c43ee8-b9d3-4e51-b73f-bd9dda66e29c") })); }
public void FromRedis_should_return_an_object_of_a_supported_type_with_an_ICollection_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); var subject = new Dictionary <string, RedisValue> { { "StringCollection", $@"{typeof(List<string>).AssemblyQualifiedName}||item1||item2||item3||\|item4" } }; var result = RedisMapper.FromRedisValues <CollectionOfStringsTestType1>(subject); Assert.That(result.StringCollection, Has.Exactly(4).Items); Assert.That( result.StringCollection, Is.EquivalentTo(new[] { "item1", "item2", "item3", "|item4" })); }
public void ToRedis_should_be_able_to_handle_list_of_Guids() { RedisMapper.RegisterType <CollectionOfGuidTestType2>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfGuidTestType2)], Has.One.Items); var subject = new CollectionOfGuidTestType2 { GuidCollection = new List <Guid> { Guid.Empty, Guid.Parse("11c43ee8-b9d3-4e51-b73f-bd9dda66e29c") } }; var result = RedisMapper.MapToRedisValues(subject); Assert.That( result["GuidCollection"], Is.EqualTo( (RedisValue) $@"{ typeof(List<Guid>).AssemblyQualifiedName }||00000000-0000-0000-0000-000000000000||11c43ee8-b9d3-4e51-b73f-bd9dda66e29c")); }
public void RegisterType_should_register_ICollection_of_string_properties() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); Assert.Contains(RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType1)], props => props.Key == "StringCollection" && props.Value == typeof(ICollection <string>)); RedisMapper.RegisterType <CollectionOfStringsTestType2>(); Assert.Contains(RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType2)], props => props.Key == "StringCollection" && props.Value == typeof(List <string>)); }
public void RegisterType_should_register_ICollection_of_Guid_properties() { RedisMapper.RegisterType <CollectionOfGuidTestType1>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfGuidTestType1)], Has.One.Matches <KeyValuePair <string, Type> >(props => props.Key == "GuidCollection" && props.Value == typeof(ICollection <Guid>))); RedisMapper.RegisterType <CollectionOfGuidTestType2>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfGuidTestType2)], Has.One.Matches <KeyValuePair <string, Type> >(props => props.Key == "GuidCollection" && props.Value == typeof(List <Guid>))); }
public void FromRedis_should_return_an_object_of_a_supported_type_without_a_collection() { RedisMapper.RegisterType <TestType1>(); var subject = new Dictionary <string, RedisValue> { { "BoolProperty", true }, { "ByteProperty", (byte)255 }, { "SByteProperty", (sbyte)-128 }, { "ShortProperty", (short)-32768 }, { "UShortProperty", (ushort)65535 }, { "IntProperty", (int)-2147483648 }, { "UIntProperty", (uint)4294967295 }, { "LongProperty", (long)-9223372036854775808 }, { "ULongProperty", ((ulong)18446744073709551615).ToString(CultureInfo.InvariantCulture) }, { "FloatProperty", 2.0f }, { "DoubleProperty", 3.0d }, { "DecimalProperty", 1234.5678m.ToString(CultureInfo.InvariantCulture) }, { "DateTimeProperty", new DateTime(2000, 1, 1, 12, 0, 0).ToString("O") }, { "CharProperty", "a" }, { "StringProperty", "teszt" }, { "GeoPositionProperty", "12.123,45.456" }, { "ByteArrayProperty", new byte[] { 0, 1, 2 } }, { "GuidProperty", Guid.Empty.ToString() }, }; var result = RedisMapper.FromRedisValues <TestType1>(subject); Assert.That(result.BoolProperty, Is.True); Assert.That(result.ByteProperty, Is.EqualTo(255)); Assert.That(result.SByteProperty, Is.EqualTo(-128)); Assert.That(result.ShortProperty, Is.EqualTo(-32768)); Assert.That(result.UShortProperty, Is.EqualTo(65535)); Assert.That(result.IntProperty, Is.EqualTo(-2147483648)); Assert.That(result.UIntProperty, Is.EqualTo(4294967295)); Assert.That(result.LongProperty, Is.EqualTo(-9223372036854775808)); Assert.That(result.ULongProperty, Is.EqualTo(18446744073709551615)); Assert.That(result.FloatProperty, Is.EqualTo(2.0f)); Assert.That(result.DoubleProperty, Is.EqualTo(3.0d)); Assert.That(result.DecimalProperty, Is.EqualTo(1234.5678m)); Assert.That(result.DateTimeProperty, Is.EqualTo(new DateTime(2000, 1, 1, 12, 0, 0))); Assert.That(result.CharProperty, Is.EqualTo('a')); Assert.That(result.StringProperty, Is.EqualTo("teszt")); Assert.That(result.GeoPositionProperty, Is.EqualTo(new GeoPosition(12.123, 45.456))); Assert.That( result.ByteArrayProperty, Is.EquivalentTo(new[] { 0, 1, 2 })); Assert.That(result.GuidProperty, Is.EqualTo(Guid.Empty)); }
public void ToRedis_should_return_a_dictionary_of_RedisValues_with_correct_values_for_objects_without_collections() { RedisMapper.RegisterType <TestType1>(); var subject = new TestType1 { BoolProperty = true, ByteProperty = 255, SByteProperty = -128, ShortProperty = -32768, UShortProperty = 65535, IntProperty = -2147483648, UIntProperty = 4294967295, LongProperty = -9223372036854775808, ULongProperty = 18446744073709551615, FloatProperty = 2.0f, DoubleProperty = 3.0d, DecimalProperty = 1234513231242123.123321321323m, DateTimeProperty = new DateTime(2000, 1, 1, 12, 0, 0), CharProperty = 'a', StringProperty = "teszt", GeoPositionProperty = new GeoPosition(12.123, 45.456), ByteArrayProperty = new byte[] { 0, 1, 2 }, GuidProperty = Guid.Empty, }; var result = RedisMapper.MapToRedisValues(subject); Assert.That(result["BoolProperty"], Is.EqualTo((RedisValue)true)); Assert.That(result["ByteProperty"], Is.EqualTo((RedisValue)255)); Assert.That(result["SByteProperty"], Is.EqualTo((RedisValue)(-128))); Assert.That(result["ShortProperty"], Is.EqualTo((RedisValue)(-32768))); Assert.That(result["UShortProperty"], Is.EqualTo((RedisValue)65535)); Assert.That(result["IntProperty"], Is.EqualTo((RedisValue)(-2147483648))); Assert.That(result["UIntProperty"], Is.EqualTo((RedisValue)4294967295)); Assert.That(result["LongProperty"], Is.EqualTo((RedisValue)(-9223372036854775808))); Assert.That(result["ULongProperty"], Is.EqualTo((RedisValue)18446744073709551615.ToString(CultureInfo.InvariantCulture))); Assert.That(result["FloatProperty"], Is.EqualTo((RedisValue)2.0f)); Assert.That(result["DoubleProperty"], Is.EqualTo((RedisValue)3.0d)); Assert.That(result["DecimalProperty"], Is.EqualTo((RedisValue)1234513231242123.123321321323m.ToString(CultureInfo.InvariantCulture))); Assert.That(result["DateTimeProperty"], Is.EqualTo((RedisValue) new DateTime(2000, 1, 1, 12, 0, 0).ToString("O"))); Assert.That(result["CharProperty"], Is.EqualTo((RedisValue)"a")); Assert.That(result["StringProperty"], Is.EqualTo((RedisValue)"teszt")); Assert.That(result["GeoPositionProperty"], Is.EqualTo((RedisValue)$"{12.123d.ToString("G17", CultureInfo.InvariantCulture)},{45.456d.ToString("G17", CultureInfo.InvariantCulture)}")); Assert.That(result["ByteArrayProperty"], Is.EqualTo((RedisValue) new byte[] { 0, 1, 2 })); Assert.That(result["GuidProperty"], Is.EqualTo((RedisValue)Guid.Empty.ToString())); }
public void ToRedis_should_be_able_to_handle_an_empty_collection_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); Assert.Equal(1, RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType1)].Count); RedisMapper.RegisterType <CollectionOfStringsTestType2>(); Assert.Equal(1, RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType2)].Count); var subject = new CollectionOfStringsTestType2 { StringCollection = new List <string>() }; var result = subject.ToRedis(); Assert.Equal($"{typeof(List<string>).AssemblyQualifiedName}", result[0].Value); }
public void ToRedis_should_be_able_to_handle_an_empty_list_of_Guids() { RedisMapper.RegisterType <CollectionOfGuidTestType2>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfGuidTestType2)], Has.One.Items); var subject = new CollectionOfGuidTestType2 { GuidCollection = new List <Guid>() }; var result = RedisMapper.MapToRedisValues(subject); Assert.That(result["GuidCollection"], Is.EqualTo((RedisValue)typeof(List <Guid>).AssemblyQualifiedName)); }
public void ToRedis_should_be_able_to_handle_an_empty_array_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); Assert.That( RedisMapper.TypesWithRegisteredProperties[typeof(CollectionOfStringsTestType1)], Has.One.Items); var subject = new CollectionOfStringsTestType1 { StringCollection = new string[0] }; var result = RedisMapper.MapToRedisValues(subject); Assert.That( result["StringCollection"], Is.EqualTo((RedisValue)typeof(string[]).AssemblyQualifiedName)); }
public void FromRedis_should_return_an_object_of_a_supported_type_with_an_ICollection_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); var subject = new[] { new HashEntry( "StringCollection", $@"{typeof(List<string>).AssemblyQualifiedName}||item1||item2||item3||\|item4") }; var result = Assert.IsType <CollectionOfStringsTestType1>(subject.FromRedis <CollectionOfStringsTestType1>()); Assert.Equal(4, result.StringCollection.Count); Assert.Contains("item1", result.StringCollection); Assert.Contains("item2", result.StringCollection); Assert.Contains("item3", result.StringCollection); Assert.Contains("|item4", result.StringCollection); }
public void ToRedis_should_be_able_to_handle_collection_of_strings() { RedisMapper.RegisterType <CollectionOfStringsTestType1>(); Assert.Equal(1, RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType1)].Count); RedisMapper.RegisterType <CollectionOfStringsTestType2>(); Assert.Equal(1, RedisMapper.RegisteredTypes[typeof(CollectionOfStringsTestType2)].Count); var subject = new CollectionOfStringsTestType2 { StringCollection = new List <string> { "item1", "item2", "item3", @"|item4" } }; var result = subject.ToRedis(); Assert.Equal($@"{typeof(List<string>).AssemblyQualifiedName}||item1||item2||item3||\|item4", result[0].Value); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvc(); services.AddTransient <IEventStore, Board.Common.Events.EventStore>(); services.AddTransient <IProjectManagerService, ProjectManagerService>(); services.AddTransient <ProjectKeyConfiguration>(provider => ProjectKeyConfiguration.Default); services.AddTransient <IProjectRepository, ProjectRepository>(); services.AddSingleton <RedisProjectViewNormalizer>(); services.AddSingleton <IEventStoreConnection>(provider => { var connectionSettings = ConnectionSettings .Create() .UseConsoleLogger() .Build(); var connection = EventStoreConnection.Create(connectionSettings, new Uri("tcp://*****:*****@localhost:1113")); connection.ConnectAsync().Wait(); return(connection); }); services.AddSingleton <IConnectionMultiplexer>(provider => ConnectionMultiplexer.Connect("localhost")); RedisMapper.RegisterType <ProjectReadModel>(); }
public void RegisterType_should_register_public_get_set_properties() { RedisMapper.RegisterType <TestType1>(); Assert.That(RedisMapper.TypesWithRegisteredProperties[typeof(TestType1)], Has.Exactly(18).Items); }
public void RegisterType_should_throw_by_default_when_an_unsupported_type_is_detected() { Assert.Throws <ArgumentException>(() => RedisMapper.RegisterType <UnsupportedPropertyTestType1>()); Assert.Throws <ArgumentException>(() => RedisMapper.RegisterType <UnsupportedPropertyTestType2>()); }
public void RegisterType_should_register_public_get_set_properties() { RedisMapper.RegisterType <TestType1>(); Assert.Equal(9, RedisMapper.RegisteredTypes[typeof(TestType1)].Count); }