internal void GivenMapFromFooDtoToFooWhenSourceIsNotNullThenMapsData() { // Arrange var fooDto = new FooDto { StringValue = "foo", IntValue = 1, DoubleValue = 1.0D, BooleanValue = true, Bar = null, Fizzes = new List <FizzDto>() }; // Act var foo = mapper.Map <Foo>(fooDto); // Assert foo.Should().NotBeNull().And.BeOfType <Foo>(); foo.StringValue.Should().Be(fooDto.StringValue); foo.IntValue.Should().Be(fooDto.IntValue * 10); foo.DoubleValue.Should().Be(fooDto.DoubleValue); foo.BooleanValue.Should().Be(!fooDto.BooleanValue); foo.Bar.Should().BeNull(); foo.Fizzes.Should().NotBeNull().And.BeEmpty(); }
public async Task CreateFoo(FooDto item) { var entity = _mapper.Map <FooEntity>(item); _context.Foos.Add(entity); await _context.SaveChangesAsync(); }
protected override void Because_of() { _destination = Mapper.Map <Foo, FooDto>(new Foo() { Id = 5, Bar = null }); }
protected override void Because_of() { _destination = Mapper.Map<Foo, FooDto>(new Foo() { Id = 5, Bar = null }); }
public void PushFooUpdateToHub_CallsUpdateFooOnHubClients() { var fooDto = new FooDto(); var hub = new FooHub(_connectionManager); hub.PushFooUpdateToHub(fooDto); _mockClient.Received().updateFoo(fooDto); }
public void TestDtoProperty() { var foo = new FooDto { Id = "1", Bar = "Fizz" }; AssertEx.IsTrue(() => foo.Bar == "Buzz"); }
static void Main() { Foo foo = new Foo("abcdefg"); FooDto dto = foo; new XmlSerializer(dto.GetType()).Serialize( Console.Out, dto); }
public async Task CreateFoo(FooDto item) { var doc = _mapper.Map <FooDoc>(item); using (var session = await _client.StartSessionAsync()) { await _collection.InsertOneAsync(session, doc); } }
public async Task CreateFoo(FooDto item) { var query = "INSERT INTO [dbo].[Foos] ([FooId], [FooTypeId], [Name], [Active]) VALUES (@FooId, @FooTypeId, @Name, @Active);"; using (var connection = new SqlConnection(_connectionString)) { await connection.ExecuteAsync(query, new { FooId = item.FooId, FooTypeId = item.FooTypeId, Name = item.Name, Active = item.Active }); } }
protected override void Because_of() { var foo1 = new Foo { Bar = new Dictionary <string, Foo> { { "lol", new Foo() } } }; _result = Mapper.Map <Foo, FooDto>(foo1); }
public void TestDtoPropertyNullWithCheck() { FooDto foo = null; AssertThrowsAssertion(() => foo != null && foo.Bar == "Buzz", @"Expected: foo != null Actual: foo = null" ); }
protected override void Because_of() { var foo = new Foo { Bar = new Bar { Value = "something" } }; foo.Bar.Foo = foo; _dto = Mapper.Map <Foo, FooDto>(foo); }
public void ObjectSet_RedisDatabase_DatabaseMethodCalledCorrectly() { var foo = new FooDto { Name = "First", Version = 123456 }; var result = _redisDatabase.ObjectSet("key", foo); Assert.That(result, Is.EqualTo(true)); _databaseMock.Verify(x => x.StringSet("somePrefixkey", JsonConvert.SerializeObject(foo), null, When.Always, CommandFlags.None), Times.Once); }
protected override void Because_of() { var source = new Foo { Value = 3, Value2 = 4 }; _destination = new FooDto { Value = 5 }; Mapper.Map(source, _destination); }
public async Task ObjectSetLifetimeAsync_RedisDatabase_DatabaseMethodCalledCorrectly() { var foo = new FooDto { Name = "First", Version = 123456 }; var result = await _redisDatabase.ObjectSetAsync("key", foo, "default"); Assert.That(result, Is.EqualTo(true)); _databaseMock.Verify(x => x.StringSetAsync("somePrefixkey", JsonConvert.SerializeObject(foo), TimeSpan.Zero, When.Always, CommandFlags.None), Times.Once); }
public void TestDtoPropertyNull() { FooDto foo = null; AssertThrowsAssertionWithStackTrace(() => foo.Bar == "Buzz", @"Expected: foo.Bar == ""Buzz"" Actual: foo = null System.NullReferenceException: Object reference not set to an instance of an object."); }
public void TestDtoProperty() { var foo = new FooDto { Id = "1", Bar = "Fizz" }; AssertThrowsAssertion(() => foo.Bar == "Buzz", @"Expected: foo.Bar == ""Buzz"" Actual: foo.Bar = ""Fizz""" ); }
public async Task HashObjectSetDictionaryAsync_RedisDatabase_DatabaseMethodCalledCorrectly() { var foo = new FooDto { Name = "First", Version = 123456 }; await _redisDatabase.HashObjectSetAsync("key", new Dictionary <string, object> { { "field", foo } }); _databaseMock.Verify(x => x.HashSetAsync("somePrefixkey", new[] { new HashEntry("field", JsonConvert.SerializeObject(foo)) }, CommandFlags.None), Times.Once); }
public async Task ObjectSetDictionaryAsync_RedisDatabase_DatabaseMethodCalledCorrectly() { var foo = new FooDto { Name = "First", Version = 123456 }; var result = await _redisDatabase.ObjectSetAsync(new Dictionary <string, object> { { "key", foo } }); Assert.That(result, Is.EqualTo(true)); _databaseMock.Verify(x => x.StringSetAsync(new[] { new KeyValuePair <RedisKey, RedisValue>("somePrefixkey", JsonConvert.SerializeObject(foo)) }, When.Always, CommandFlags.None), Times.Once); }
private static void SaveFooWithRelation() { var value = new FooDto { FooId = Guid.NewGuid(), FooName = $"[F] - {DateTime.UtcNow.ToString("G")}", BarId = Guid.NewGuid(), BarName = $"[B] - {DateTime.UtcNow.ToString("G")}" }; _connection.SaveFooDto(value); Console.WriteLine($"Value saved: [F]:{value.FooId} [B]:{value.BarId}"); Console.WriteLine(); }
protected override void Because_of() { var source = new FooDto { Values = new List <DestinationValuePair> { new DestinationValuePair { Key = "Key1", Value = "Value1" }, new DestinationValuePair { Key = "Key2", Value = "Value2" } }.ToArray() }; _result = Mapper.Map <FooDto, FooObject>(source); }
public void JsonConverter_Test() { var fooDto = new FooDto { Name = "foo-dto", BarDtos = new List <BarDto>() }; fooDto.SetProperty("foo", "foo-value"); var barDto = new BarDto { Name = "bar-dto" }; barDto.SetProperty("bar", "bar-value"); fooDto.BarDtos.Add(barDto); var json = _jsonSerializer.Serialize(fooDto); fooDto = _jsonSerializer.Deserialize <FooDto>(json); fooDto.ShouldNotBeNull(); fooDto.Name.ShouldBe("foo-dto"); fooDto.GetProperty("foo").ShouldBe("foo-value"); fooDto.BarDtos.Count.ShouldBe(1); fooDto.BarDtos.First().Name.ShouldBe("bar-dto"); fooDto.BarDtos.First().GetProperty("bar").ShouldBe("bar-value"); fooDto.Name = "new-foo-dto"; fooDto.SetProperty("foo", "new-foo-value"); fooDto.BarDtos.First().Name = "new-bar-dto"; fooDto.BarDtos.First().SetProperty("bar", "new-bar-value"); json = _jsonSerializer.Serialize(fooDto); fooDto = _jsonSerializer.Deserialize <FooDto>(json); fooDto.ShouldNotBeNull(); fooDto.Name.ShouldBe("new-foo-dto"); fooDto.GetProperty("foo").ShouldBe("new-foo-value"); fooDto.BarDtos.Count.ShouldBe(1); fooDto.BarDtos.First().Name.ShouldBe("new-bar-dto"); fooDto.BarDtos.First().GetProperty("bar").ShouldBe("new-bar-value"); }
public void SaveFooDto(FooDto dto) { try { _connection.Open(); var sql = $@" INSERT INTO Bar(Id, Name) VALUES('{dto.BarId}', '{dto.BarName}'); INSERT INTO Foo(Id, Name, BarId) VALUES('{dto.FooId}', '{dto.FooName}', '{dto.BarId}')" ; _connection.Execute(sql); } catch (SqliteException ex) { throw; } finally { _connection.Close(); } }
public void TestDtoPropertyNull() { FooDto foo = null; AssertEx.IsTrue(() => foo.Bar == "Buzz"); }
private bool Equals(FooDto other) { return(string.Equals(Name, other.Name) && Version == other.Version); }
static void Main(string[] args) { //This goes in the startup var automapperConfig = new AutoMapperConfig().RegisterMappings(); //Every single member has correlation with destination type. //It may not be the right one (since there are always exception cases), //but it at least tests that every property is moved from source type to destination. //will throw exception if not valid. automapperConfig.AssertConfigurationIsValid(); //Get foo and bar entities from database var fooEntity = new FooEntity() { EmployeeFName = "Foo", EmployeeLName = "Fooster" }; var barEntity = new BarEntity() { PersonFirstName = "Bar", PersonLastName = "Cluster" }; // auto map Entity to DTO var dtoFooModel = Mapper.Map(fooEntity, new FooDto(), typeof(FooEntity), typeof(DTO.FooDto)); var dtoBarModel = Mapper.Map(barEntity, new BarDto(), typeof(BarEntity), typeof(DTO.BarDto)); // Auto Map DTO Back to Entities var fooDTOFromUI = new FooDto() { EmployeeFName = "FooBackToEntity", EmployeeLName = "From Foo DTO" }; var barDTOFromUI = new BarDto() { PersonFName = "BarBackToEntity", PersonLName = "FROM Bar DTO" }; var entityFooModel = Mapper.Map(fooDTOFromUI, new FooEntity(), typeof(FooDto), typeof(FooEntity)); var entityBarModel = Mapper.Map(barDTOFromUI, new BarEntity(), typeof(BarDto), typeof(BarEntity)); //Get AddressEntity from database var addressEntity = new AddressEntity() { Street = "1751 Granger Cir", City = "Castle Rock", State = "CO", Zip = "80109" }; // auto map Entity to DTO var addressDto = new AddressDisplayOnlyDto(); Mapper.Map(addressEntity, addressDto, typeof(AddressEntity), typeof(AddressDisplayOnlyDto)); var p = addressDto.CompleteAddress; Console.WriteLine(p); Console.ReadKey(); //Get Person and Address entity from database PersonEntity personEntity = new PersonEntity() { FirstName = "Eric", LastName = "Norton", PersonAddress = addressEntity }; //Map person entity and personEntity.Address to personDto var dtoPersonModel = Mapper.Map(personEntity, new PersonDto(), typeof(PersonEntity), typeof(PersonDto)); //Get Person DTO from UI PersonDto personDto = new PersonDto() { FName = "Eric", LName = "Nordin", Street = "345 West Green St", City = "Castle Rock", State = "CO", ZipCode = "44565" }; //Get Person DTO from UI and map back to person entity and address entity PersonEntity entityPersonModel = Mapper.Map(personDto, new PersonEntity(), typeof(PersonDto), typeof(PersonEntity)) as PersonEntity; }
public void TestDtoPropertyNullWithCheck() { FooDto foo = null; AssertEx.IsTrue(() => foo != null && foo.Bar == "Buzz"); }
public void PushFooUpdateToHub(FooDto fooDto) { var context = _connectionManager.GetHubContext <FooHub>(); context.Clients.All.updateFoo(fooDto); }
public async Task <IActionResult> Create([FromBody] FooDto item) { await _manager.CreateFoo(item); return(Ok()); }