本文整理汇总了C#中InMemoryRepository类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRepository类的具体用法?C# InMemoryRepository怎么用?C# InMemoryRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryRepository类属于命名空间,在下文中一共展示了InMemoryRepository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetTestableChat
public static TestableChat GetTestableChat(string connectionId, StateChangeTracker clientState, ChatUser user, IDictionary<string, Cookie> cookies)
{
// setup things needed for chat
var repository = new InMemoryRepository();
var resourceProcessor = new Mock<IResourceProcessor>();
var chatService = new Mock<IChatService>();
var connection = new Mock<IConnection>();
var settings = new Mock<IApplicationSettings>();
var mockPipeline = new Mock<IHubPipelineInvoker>();
// add user to repository
repository.Add(user);
// create testable chat
var chat = new TestableChat(settings, resourceProcessor, chatService, repository, connection);
var mockedConnectionObject = chat.MockedConnection.Object;
chat.Clients = new HubConnectionContext(mockPipeline.Object, mockedConnectionObject, "Chat", connectionId, clientState);
var prinicipal = new Mock<IPrincipal>();
var request = new Mock<IRequest>();
request.Setup(m => m.Cookies).Returns(cookies);
request.Setup(m => m.User).Returns(prinicipal.Object);
// setup context
chat.Context = new HubCallerContext(request.Object, connectionId);
return chat;
}
开发者ID:ucdavis,项目名称:JabbR,代码行数:30,代码来源:ChatFacts.cs
示例2: GetTestableChat
public static TestableChat GetTestableChat(string clientId, TrackingDictionary clientState, ChatUser user, NameValueCollection cookies)
{
// setup things needed for chat
var repository = new InMemoryRepository();
var resourceProcessor = new Mock<IResourceProcessor>();
var chatService = new Mock<IChatService>();
var connection = new Mock<IConnection>();
// add user to repository
repository.Add(user);
// create testable chat
var chat = new TestableChat(resourceProcessor, chatService, repository, connection);
var mockedConnectionObject = chat.MockedConnection.Object;
// setup client agent
chat.Agent = new ClientAgent(mockedConnectionObject, "Chat");
var request = new Mock<IRequest>();
request.Setup(m => m.Cookies).Returns(cookies);
// setup signal agent
var prinicipal = new Mock<IPrincipal>();
chat.Caller = new SignalAgent(mockedConnectionObject, clientId, "Chat", clientState);
// setup context
chat.Context = new HubContext(new HostContext(request.Object, null, prinicipal.Object), clientId);
return chat;
}
开发者ID:skoon,项目名称:JabbR,代码行数:30,代码来源:ChatFacts.cs
示例3: ThrowsIfNameIsInValid
public void ThrowsIfNameIsInValid()
{
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("some in valid name", clientId: null, userAgent: null, password: null));
}
开发者ID:dkouznet3,项目名称:JabbR,代码行数:7,代码来源:ChatServiceFacts.cs
示例4: SharpRepository_Supports_Basic_Crud_Operations
public void SharpRepository_Supports_Basic_Crud_Operations()
{
// Declare your generic InMemory Repository.
// Check out HowToAbstractAwayTheGenericRepository.cs for cleaner ways to new up a repo.
var repo = new InMemoryRepository<Order, int>();
// Create
var create = new Order { Name = "Big sale" };
repo.Add(create);
const int expectedOrderId = 1;
create.OrderId.ShouldEqual(expectedOrderId);
// Read
var read = repo.Get(expectedOrderId);
read.Name.ShouldEqual(create.Name);
// Update
read.Name = "Really big sale";
repo.Update(read);
var update = repo.Get(expectedOrderId);
update.OrderId.ShouldEqual(expectedOrderId);
update.Name.ShouldEqual(read.Name);
// Delete
repo.Delete(update);
var delete = repo.Get(expectedOrderId);
delete.ShouldBeNull();
}
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:30,代码来源:GettingStarted.cs
示例5: ThrowsIfPasswordIsTooShort
public void ThrowsIfPasswordIsTooShort()
{
var repository = new InMemoryRepository();
var service = new MembershipService(repository, new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("SomeUser", "email", password: "short"));
}
开发者ID:QuinntyneBrown,项目名称:JabbR,代码行数:7,代码来源:ChatServiceFacts.cs
示例6: ThrowsIfNameIsInValid
public void ThrowsIfNameIsInValid()
{
var repository = new InMemoryRepository();
var service = new MembershipService(repository, new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("some in valid name", "email", password: null));
}
开发者ID:QuinntyneBrown,项目名称:JabbR,代码行数:7,代码来源:ChatServiceFacts.cs
示例7: Should_return_matches_from_a_repository
public void Should_return_matches_from_a_repository()
{
var users = new List<InstalledPlugin>
{
new InstalledPlugin { Id = Guid.NewGuid(), Name = "Blog", Version = "1.0.0"},
new InstalledPlugin { Id = Guid.NewGuid(), Name = "News", Version = "1.0.0"},
new InstalledPlugin { Id = Guid.NewGuid(), Name = "Events", Version = "1.0.0"}
};
IRepository<InstalledPlugin> repository = new InMemoryRepository<InstalledPlugin>(users);
var matches = repository.Find(new OrderedPlugins());
Assert.AreEqual(3, matches.Count);
var count = 0;
foreach (var item in matches)
{
if (count == 0)
Assert.AreEqual("Blog", item.Name);
if (count == 1)
Assert.AreEqual("Events", item.Name);
if (count == 2)
Assert.AreEqual("News", item.Name);
count++;
}
}
开发者ID:pollingj,项目名称:Membrane-CMS,代码行数:27,代码来源:OrderedPluginFixture.cs
示例8: CanCreateInstanceOfRepository
public void CanCreateInstanceOfRepository()
{
IRepository<SomeEntity> repo = new InMemoryRepository<SomeEntity>();
Assert.IsNotNull(repo);
Assert.IsInstanceOf<InMemoryRepository<SomeEntity>>(repo);
}
开发者ID:happygrizzly,项目名称:C--Event-Processors-Example,代码行数:7,代码来源:InMemoryRepositoryTests.cs
示例9: ThrowsIfPasswordIsTooShort
public void ThrowsIfPasswordIsTooShort()
{
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("SomeUser", clientId: null, userAgent: null, password: "short"));
}
开发者ID:dkouznet3,项目名称:JabbR,代码行数:7,代码来源:ChatServiceFacts.cs
示例10: GetMessageRepository
public static InMemoryRepository<Message> GetMessageRepository(int numberOfMessage = 25)
{
var repo = new InMemoryRepository<Message>();
var friendship = new Friendship()
{
Id = 1,
IsFirstUserSender = true,
FirstUserId = "12345",
SecondUserId = "54321",
CreatedOn = DateTime.Now,
IsApproved = true
};
for (var i = 0; i < numberOfMessage; i++)
{
var date = new DateTime(2015, 11, 5, 23, 47, 12);
date.AddDays(i);
repo.Add(new Message
{
Id = i,
Author = new User
{
FirstName = "FName" + i,
LastName = "LName" + i,
ProfilePhoto = new byte[i]
},
Content = "Content" + i,
SentOn = date,
FriendshipId = friendship.Id
});
}
return repo;
}
开发者ID:Nikolay-D,项目名称:WebChat,代码行数:35,代码来源:TestObjectFactory.cs
示例11: MainWindow
public MainWindow()
{
InitializeComponent();
// Use this as construction root for simplicity.
// In real world app there should be good framework for this and this should be done
// outside of main window for reason that then mainwindow is interchangeable too if required.
var dataSource = new InMemoryRepository();
// Dummy data for testing...
dataSource.Add(new CarImage {Color="Black", RegisterPlate = "ABC-123", Speed = 140});
var messenger = new MessageAggregator();
var reportViewModel = new ReportViewModel(dataSource, messenger);
var colorFilter = new ColorFilterViewModel();
var filterViewModel = new FiltersViewModel(new List<IFilter> {colorFilter}, messenger);
// Just for testing, apply dummy filter so that data is shown.
messenger.Publish(new Messages.FiltersAppliedMessage());
DataContext = new
{
Report = reportViewModel,
Filters = filterViewModel
};
}
开发者ID:savpek,项目名称:CSharp-Demo,代码行数:26,代码来源:MainWindow.xaml.cs
示例12: MakesOwnerAllowedIfRoomLocked
public void MakesOwnerAllowedIfRoomLocked()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
var user2 = new ChatUser
{
Name = "foo2"
};
repository.Add(user);
repository.Add(user2);
var room = new ChatRoom
{
Name = "Room",
Creator = user,
Private = true
};
room.Owners.Add(user);
user.OwnedRooms.Add(room);
user.Rooms.Add(room);
room.Users.Add(user);
var service = new ChatService(repository, new Mock<ICryptoService>().Object);
service.AddOwner(user, user2, room);
Assert.True(user2.AllowedRooms.Contains(room));
Assert.True(room.AllowedUsers.Contains(user2));
Assert.True(room.Owners.Contains(user2));
Assert.True(user2.OwnedRooms.Contains(room));
}
开发者ID:Polows,项目名称:JabbR,代码行数:33,代码来源:ChatServiceFacts.cs
示例13: MakesUserOwner
public void MakesUserOwner()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
var user2 = new ChatUser
{
Name = "foo2"
};
repository.Add(user);
repository.Add(user2);
var room = new ChatRoom
{
Name = "Room",
Creator = user
};
room.Owners.Add(user);
user.OwnedRooms.Add(room);
user.Rooms.Add(room);
room.Users.Add(user);
var service = new ChatService(repository);
service.AddOwner(user, user2, room);
Assert.True(room.Owners.Contains(user2));
Assert.True(user2.OwnedRooms.Contains(room));
}
开发者ID:kiliman,项目名称:JabbR,代码行数:30,代码来源:ChatServiceFacts.cs
示例14: Should_return_matches_from_a_repository
public void Should_return_matches_from_a_repository()
{
var users = new List<UserGroup>
{
new UserGroup {Id = Guid.NewGuid(), Name = "First Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "Second Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "Third Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "News Editor Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "Publishing Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "Blogging Group"},
new UserGroup {Id = Guid.NewGuid(), Name = "Product Editing Group"}
};
IRepository<UserGroup> repository = new InMemoryRepository<UserGroup>(users);
var matches = repository.Find(new PagedUserGroups(3, 3));
Assert.AreEqual(3, matches.Count);
var count = 0;
foreach (var item in matches)
{
if (count == 0)
Assert.AreEqual("News Editor Group", item.Name);
if (count == 1)
Assert.AreEqual("Publishing Group", item.Name);
if (count == 2)
Assert.AreEqual("Blogging Group", item.Name);
count++;
}
}
开发者ID:pollingj,项目名称:Membrane-CMS,代码行数:31,代码来源:PagedUserGroupsFixture.cs
示例15: GetTestableChat
public static TestableChat GetTestableChat(string connectionId, TrackingDictionary clientState, ChatUser user, NameValueCollection cookies)
{
// setup things needed for chat
var repository = new InMemoryRepository();
var resourceProcessor = new Mock<IResourceProcessor>();
var chatService = new Mock<IChatService>();
var connection = new Mock<IConnection>();
var settings = new Mock<IApplicationSettings>();
settings.Setup(m => m.AuthApiKey).Returns("key");
// add user to repository
repository.Add(user);
// create testable chat
var chat = new TestableChat(settings, resourceProcessor, chatService, repository, connection);
var mockedConnectionObject = chat.MockedConnection.Object;
// setup client agent
chat.Clients = new ClientProxy(mockedConnectionObject, "Chat");
// setup signal agent
var prinicipal = new Mock<IPrincipal>();
var request = new Mock<IRequest>();
request.Setup(m => m.Cookies).Returns(new Cookies(cookies));
request.Setup(m => m.User).Returns(prinicipal.Object);
chat.Caller = new StatefulSignalProxy(mockedConnectionObject, connectionId, "Chat", clientState);
// setup context
chat.Context = new HubCallerContext(request.Object, connectionId);
return chat;
}
开发者ID:rajjan,项目名称:JabbR,代码行数:35,代码来源:ChatFacts.cs
示例16: CachingEnabled_Should_Be_True_When_CachingStrategy_Is_Changed_From_NoCachingStrategy
public void CachingEnabled_Should_Be_True_When_CachingStrategy_Is_Changed_From_NoCachingStrategy()
{
var repository = new InMemoryRepository<Contact, Int32>(new NoCachingStrategy<Contact, int>());
repository.CachingEnabled.ShouldBeFalse();
repository.CachingStrategy = new TimeoutCachingStrategy<Contact, int>(60);
repository.CachingEnabled.ShouldBeTrue();
}
开发者ID:SharpRepository,项目名称:SharpRepository,代码行数:7,代码来源:CacheEnabledSpike.cs
示例17: Repository_Handles_Sorting
public void Repository_Handles_Sorting()
{
var repo = new InMemoryRepository<Order>();
repo.Add(OrdersToLoad());
// there are 2 ways to handle sorting, there is an Expression based way
// and a "magic string" based approach.
// Why the 2 approaches?
// For convenience really. In a Web based applicaiton sometimes it is easier to
// post back a string that represents the properrty that you want to sort on.
// First, the Expression way
var descendingOrders = repo.GetAll(new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: true));
descendingOrders.First().OrderId.ShouldEqual(1);
var ascendingOrders = repo.GetAll(new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: false));
ascendingOrders.First().OrderId.ShouldEqual(2);
// You can also combine sortings and selectors (See HowToUseGetSelectors for more info)
var descendingNames = repo.GetAll(x => x.Name, new SortingOptions<Order, DateTime>(x => x.OrderDate, isDescending: true));
descendingNames.First().ShouldEqual("Order 1");
// The Magic String approach to sorting
// you can see that you don't need the second generic type (the property type to sort on), just the name of the property
ascendingOrders = repo.GetAll(new SortingOptions<Order>("OrderDate", isDescending: false));
ascendingOrders.First().OrderId.ShouldEqual(2);
// using sorting with FindAll
var minDate = DateTime.Now.AddDays(-7);
var ordersWithinAWeek = repo.FindAll(x => x.OrderDate > minDate, new SortingOptions<Order, double>(x => x.Total, true));
ordersWithinAWeek.Count().ShouldEqual(2);
}
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:32,代码来源:HowToUsePagingAndSorting.cs
示例18: When_a_user_is_successfully_logged_in
public When_a_user_is_successfully_logged_in()
{
var username = "[email protected]";
var password = "a";
Repository = new InMemoryRepository<User>(SecurityHelper.GetUserList());
UserService = new UsersService(Repository);
CurrentUser = UserService.LoginUser(username, password);
}
开发者ID:preetksingh80,项目名称:BlogSite,代码行数:8,代码来源:When_a_user_is_successfully_logged_in.cs
示例19: delete_removes_from_internal_list
public void delete_removes_from_internal_list()
{
var list = new List<string> { "Apple", "Ball", "Cat", "Dog" };
var repository = new InMemoryRepository<string>(list);
repository.Delete("Apple");
Assert.That(list.Contains("Apple"), Is.False);
}
开发者ID:jordanyaker,项目名称:ncommon,代码行数:8,代码来源:InMemoryRepositoryTests.cs
示例20: Add_adds_to_internal_list
public void Add_adds_to_internal_list()
{
var list = new List<string> { "Apple", "Ball", "Cat", "Dog" };
var repository = new InMemoryRepository<string>(list);
repository.Add("DoDo");
Assert.That(list.Contains("DoDo"));
}
开发者ID:jordanyaker,项目名称:ncommon,代码行数:8,代码来源:InMemoryRepositoryTests.cs
注:本文中的InMemoryRepository类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论