本文整理汇总了C#中InMemoryRepository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRepository.Add方法的具体用法?C# InMemoryRepository.Add怎么用?C# InMemoryRepository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InMemoryRepository
的用法示例。
在下文中一共展示了InMemoryRepository.Add方法的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: 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));
}
示例4: 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));
}
示例5: Repository_Supports_Selectors
public void Repository_Supports_Selectors()
{
var repo = new InMemoryRepository<Order>();
// let's add a couple of orders to work with
repo.Add(new Order()
{
Name = "Order 1",
Total = 120.00,
OrderDate = new DateTime(2013, 4, 26)
});
repo.Add(new Order()
{
Name = "Order 2",
Total = 80.00,
OrderDate = new DateTime(2013, 4, 24)
});
// normal Get method
var order = repo.Get(1);
order.OrderId.ShouldEqual(1);
// in this case we only need the order name
var orderName = repo.Get(1, x => x.Name);
orderName.ShouldEqual("Order 1");
// we can also bring back an anonymous type if needed
var anonymousType = repo.Get(1, x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 });
anonymousType.IsExpensiveOrder.ShouldBeTrue();
// or we can map it to a specific type we have defined like a ViewModel
var viewModel = repo.Get(1, x => new OrderViewModel() {Name = x.Name, IsExpensiveOrder = x.Total > 100.0});
viewModel.IsExpensiveOrder.ShouldBeTrue();
// We have the same options with the GetAll, Find and FindAll as well
orderName = repo.Find(x => x.OrderId == 2, x => x.Name);
orderName.ShouldEqual("Order 2");
// we can also bring back an anonymous type if needed
var anonymousTypes = repo.GetAll(x => new { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
anonymousTypes.Count.ShouldEqual(2);
anonymousTypes.First().Name.ShouldEqual("Order 1");
anonymousTypes.First().IsExpensiveOrder.ShouldBeTrue();
anonymousTypes.Last().Name.ShouldEqual("Order 2");
anonymousTypes.Last().IsExpensiveOrder.ShouldBeFalse();
// or we can map it to a specific type we have defined like a ViewModel
var viewModels = repo.FindAll(x => x.OrderId < 5, x => new OrderViewModel() { Name = x.Name, IsExpensiveOrder = x.Total > 100.0 }).ToList();
viewModels.Count.ShouldEqual(2);
viewModels.First().Name.ShouldEqual("Order 1");
viewModels.First().IsExpensiveOrder.ShouldBeTrue();
viewModels.Last().Name.ShouldEqual("Order 2");
viewModels.Last().IsExpensiveOrder.ShouldBeFalse();
}
示例6: CreateRepository
public static IRepository CreateRepository()
{
var repository = new InMemoryRepository();
repository.Add(new CarImage {Color = "Blue", RegisterPlate = "IOA-303", Speed = 93});
repository.Add(new CarImage {Color = "Blue", RegisterPlate = "IOB-301", Speed = 75});
repository.Add(new CarImage {Color = "Red", RegisterPlate = "IAC-300", Speed = 84});
repository.Add(new CarImage {Color = "Black", RegisterPlate = "AOB-201", Speed = 120});
repository.Add(new CarImage {Color = "Red", RegisterPlate = "BOB-101", Speed = 90});
return repository;
}
示例7: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
var repository = new InMemoryRepository<Product>();
repository.Add(new Product { Available = 10, Title = "Snuten i Hollywood I", ImageFilePath = "Content/images/snuten_i_hollywood_i.jpg", Price = 99m});
repository.Add(new Product { Available = 30, Title = "Snuten i Hollywood II", ImageFilePath = "Content/images/snuten_i_hollywood_ii.jpg", Price = 199m });
repository.Add(new Product { Available = 66, Title = "Snuten i Hollywood III", ImageFilePath = "Content/images/snuten_i_hollywood_iii.jpg", Price = 49m });
repository.Add(new Product { Available = 78, Title = "Snuten i Hollywood IV", ImageFilePath = "Content/images/snuten_i_hollywood_iv.jpg", Price = 69m });
}
示例8: ExecuteFindAll_With_Selector_Should_Use_Cache_After_First_Call
public void ExecuteFindAll_With_Selector_Should_Use_Cache_After_First_Call()
{
var repos = new InMemoryRepository<Contact>(new StandardCachingStrategy<Contact>());
repos.Add(new Contact { Name = "Test1" });
repos.Add(new Contact { Name = "Test2" });
var items = repos.FindAll(x => x.ContactId < 3, x => x.Name);
repos.CacheUsed.ShouldBeFalse();
items.Count().ShouldEqual(2);
items = repos.FindAll(x => x.ContactId < 3, x => x.Name);
repos.CacheUsed.ShouldBeTrue();
items.Count().ShouldEqual(2);
}
示例9: ExecuteFind_Should_Use_Cache_After_First_Call
public void ExecuteFind_Should_Use_Cache_After_First_Call()
{
var repos = new InMemoryRepository<Contact>(new StandardCachingStrategy<Contact>());
repos.Add(new Contact { Name = "Test1" });
repos.Add(new Contact { Name = "Test2" });
var item= repos.Find(x => x.ContactId == 1);
repos.CacheUsed.ShouldBeFalse();
item.ShouldNotBeNull();
item = repos.Find(x => x.ContactId == 1);
repos.CacheUsed.ShouldBeTrue();
item.ShouldNotBeNull();
}
示例10: 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);
}
示例11: Logging_Via_Aspects
public void Logging_Via_Aspects()
{
var repository = new InMemoryRepository<Contact, int>();
var contact1 = new Contact() {Name = "Contact 1"};
repository.Add(contact1);
repository.Add(new Contact() { Name = "Contact 2"});
repository.Add(new Contact() { Name = "Contact 3"});
contact1.Name += " EDITED";
repository.Update(contact1);
repository.Delete(2);
repository.FindAll(x => x.ContactId < 50);
}
示例12: 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
};
}
示例13: 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;
}
示例14: 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();
}
示例15: 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"));
}