public void LoginTest() { const string userName = "******"; const string password = "******"; var dataAccess = Mock.Interface<IDataAccess>(); var expectedUser = new User { Email = userName, Password = PasswordHash.HashPassword (password), PhoneNumber = "000-000-0000", }; var users = new [] { expectedUser }; Expect.MethodCall( () => dataAccess.All<User>() ).Returns( users.AsQueryable() ); var userService = new UserService(dataAccess); User actualUser; userService.Login(userName, password, out actualUser); Assert.IsTrue(actualUser == expectedUser); }
public void Can_map_custom_mapped_properties() { Mapper.Initialize(cfg => cfg.CreateMap<Source, Dest>().ForMember(d => d.Bar, opt => opt.MapFrom(src => src.Foo))); Expression<Func<Dest, bool>> expr = d => d.Bar == 10; var mapped = Mapper.Map<Expression<Func<Dest, bool>>, Expression<Func<Source, bool>>>(expr); var items = new[] { new Source {Foo = 10}, new Source {Foo = 10}, new Source {Foo = 15} }; items.AsQueryable().Where(mapped).Count().ShouldBe(2); }
public void Can_map_flattened_properties() { Mapper.Initialize(cfg => cfg.CreateMap<Source, Dest>()); Expression<Func<Dest, bool>> expr = d => d.ChildValue == 10; var mapped = Mapper.Map<Expression<Func<Dest, bool>>, Expression<Func<Source, bool>>>(expr); var items = new[] { new Source {Child = new ChildSrc {Value = 10}}, new Source {Child = new ChildSrc {Value = 10}}, new Source {Child = new ChildSrc {Value = 15}} }; items.AsQueryable().Where(mapped).Count().ShouldBe(2); }
public void DataContractJsonSerializerSerializesAggregates() { using (var stream = new MemoryStream()) { var serializer = new DataContractJsonSerializer(typeof(DataSourceResult), new [] { typeof (Person) }); var people = new[] { new Person { Age = 30 }, new Person { Age = 30 } }; serializer.WriteObject(stream, people.AsQueryable().ToDataSourceResult(1, 2, null, null, new [] { new Aggregator { Aggregate = "sum", Field = "Age" } })); var json = Encoding.UTF8.GetString(stream.ToArray()).Replace("\"__type\":\"DynamicClass2:#\",", ""); Assert.AreEqual("{\"Aggregates\":{\"Age\":{\"sum\":60}},\"Data\":[],\"Total\":2}", json); } }
public void Can_map_with_different_destination_types() { Mapper.Initialize(cfg => cfg.CreateMap<Source, Dest>().ForMember(d => d.Bar, opt => opt.MapFrom(src => src.Foo))); Expression<Func<Dest, Dest>> expr = d => d; var mapped = Mapper.Map<Expression<Func<Dest, Dest>>, Expression<Func<Source, Source>>>(expr); var items = new[] { new Source {Foo = 10}, new Source {Foo = 10}, new Source {Foo = 15} }; var items2 = items.AsQueryable().Select(mapped).ToList(); }