forked from MapsterMapper/Mapster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added locks for caching when running on multiple threads
- Loading branch information
Showing
3 changed files
with
169 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace Fpr.Tests | ||
{ | ||
[TestFixture] | ||
public class WhenRunningOnMultipleThreads | ||
{ | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
TypeAdapterConfig<Customer, CustomerDTO>.Clear(); | ||
TypeAdapterConfig<Address, AddressDTO>.Clear(); | ||
} | ||
|
||
[Test] | ||
public void Can_Set_Up_Mapping_On_Multiple_Threads() | ||
{ | ||
Parallel.For(1, 5, x => TypeAdapterConfig<Customer, CustomerDTO>.NewConfig()); | ||
} | ||
|
||
[Test] | ||
public void Can_Set_Up_Adapt_On_Multiple_Threads() | ||
{ | ||
Parallel.For(1, 5, x => TypeAdapter.Adapt<Customer, CustomerDTO>(GetCustomer())); | ||
} | ||
|
||
|
||
private static Customer GetCustomer() | ||
{ | ||
Customer c = new Customer() | ||
{ | ||
Address = new Address() { City = "istanbul", Country = "turkey", Id = 1, Street = "istiklal cad." }, | ||
HomeAddress = new Address() { City = "istanbul", Country = "turkey", Id = 2, Street = "istiklal cad." }, | ||
Id = 1, | ||
Name = "Kıvanç", | ||
Credit = 234.7m, | ||
WorkAddresses = new List<Address>() { | ||
new Address() { City = "istanbul", Country = "turkey", Id = 5, Street = "istiklal cad." }, | ||
new Address() { City = "izmir", Country = "turkey", Id = 6, Street = "konak" } | ||
}, | ||
Addresses = new List<Address>() { | ||
new Address() { City = "istanbul", Country = "turkey", Id = 3, Street = "istiklal cad." }, | ||
new Address() { City = "izmir", Country = "turkey", Id = 4, Street = "konak" } | ||
}.ToArray() | ||
}; | ||
|
||
return c; | ||
} | ||
|
||
|
||
#region Test Classes | ||
|
||
public class Address | ||
{ | ||
public int Id { get; set; } | ||
public string Street { get; set; } | ||
public string City { get; set; } | ||
public string Country { get; set; } | ||
} | ||
|
||
public class AddressDTO | ||
{ | ||
public int Id { get; set; } | ||
public string City { get; set; } | ||
public string Country { get; set; } | ||
} | ||
|
||
public class Customer | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public decimal? Credit { get; set; } | ||
public Address Address { get; set; } | ||
public Address HomeAddress { get; set; } | ||
public Address[] Addresses { get; set; } | ||
public ICollection<Address> WorkAddresses { get; set; } | ||
} | ||
|
||
public class CustomerDTO | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public Address Address { get; set; } | ||
public AddressDTO HomeAddress { get; set; } | ||
public AddressDTO[] Addresses { get; set; } | ||
public List<AddressDTO> WorkAddresses { get; set; } | ||
public string AddressCity { get; set; } | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters