本文整理汇总了C#中InMemoryRepository类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRepository类的具体用法?C# InMemoryRepository怎么用?C# InMemoryRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryRepository类属于命名空间,在下文中一共展示了InMemoryRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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));
}
示例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();
}
示例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"));
}
示例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));
}
示例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++;
}
}
示例8: CanCreateInstanceOfRepository
public void CanCreateInstanceOfRepository()
{
IRepository<SomeEntity> repo = new InMemoryRepository<SomeEntity>();
Assert.IsNotNull(repo);
Assert.IsInstanceOf<InMemoryRepository<SomeEntity>>(repo);
}
示例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"));
}
示例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;
}
示例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
};
}
示例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));
}
示例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));
}
示例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++;
}
}
示例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;
}