本文整理汇总了C#中Raven.Tests.Document.Company类的典型用法代码示例。如果您正苦于以下问题:C# Company类的具体用法?C# Company怎么用?C# Company使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Company类属于Raven.Tests.Document命名空间,在下文中一共展示了Company类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_promote_transactions
public void Can_promote_transactions()
{
var documentStore = new DocumentStore {Url = "http://localhost:8080"};
documentStore.Initialize();
var company = new Company {Name = "Company Name"};
using (var tx = new TransactionScope())
{
var session = documentStore.OpenSession();
session.Store(company);
session.SaveChanges();
Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
using (var session3 = documentStore.OpenSession())
{
session3.Store(new Company {Name = "Another company"});
session3.SaveChanges(); // force a dtc promotion
Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
}
tx.Complete();
}
for (int i = 0; i < 15; i++)// wait for commit
{
using (var session2 = documentStore.OpenSession())
if (session2.Load<Company>(company.Id) != null)
break;
Thread.Sleep(100);
}
using (var session2 = documentStore.OpenSession())
Assert.NotNull((session2.Load<Company>(company.Id)));
}
示例2: WhenUsingShardedServers
public WhenUsingShardedServers()
{
const string server = "localhost";
const int port1 = 8079;
const int port2 = 8081;
path1 = GetPath("TestShardedDb1");
path2 = GetPath("TestShardedDb2");
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);
company1 = new Company { Name = "Company1" };
company2 = new Company { Name = "Company2" };
server1 = GetNewServer(port1, path1);
server2 = GetNewServer(port2, path2);
shards = new List<IDocumentStore> {
new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1},
new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2}
}.ToDictionary(x => x.Identifier, x => x);
shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
shardResolution.Stub(x => x.GenerateShardIdFor(company1)).Return("Shard1");
shardResolution.Stub(x => x.GenerateShardIdFor(company2)).Return("Shard2");
shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");
shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
}
示例3: Can_insert_into_two_servers_running_simultaneously_without_sharding
public void Can_insert_into_two_servers_running_simultaneously_without_sharding()
{
var serversStoredUpon = new List<string>();
using (var server1 = GetNewServer(port1, path1))
using (var server2 = GetNewServer(port2, path2))
{
foreach (var port in new[] { port1, port2 })
{
using (var documentStore = new DocumentStore { Url = "http://localhost:"+ port }.Initialize())
using (var session = documentStore.OpenSession())
{
documentStore.Stored += (sender, args) => serversStoredUpon.Add(args.SessionIdentifier);
var entity = new Company { Name = "Company" };
session.Store(entity);
session.SaveChanges();
Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
}
}
}
Assert.Contains(port1.ToString(), serversStoredUpon[0]);
Assert.Contains(port2.ToString(), serversStoredUpon[1]);
}
示例4: Can_promote_transactions
public void Can_promote_transactions()
{
var documentStore = new DocumentStore {Url = "http://localhost:8080"};
documentStore.Initialize();
var company = new Company {Name = "Company Name"};
using (var tx = new TransactionScope())
{
var session = documentStore.OpenSession();
session.Store(company);
session.SaveChanges();
Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
new ManyDocumentsViaDTC.DummyEnlistmentNotification(), EnlistmentOptions.None);
Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
tx.Complete();
}
for (int i = 0; i < 15; i++)// wait for commit
{
using (var session2 = documentStore.OpenSession())
if (session2.Load<Company>(company.Id) != null)
break;
Thread.Sleep(100);
}
using (var session2 = documentStore.OpenSession())
Assert.NotNull((session2.Load<Company>(company.Id)));
}
示例5: CanPerformASimpleWhere
public IEnumerable<Task> CanPerformASimpleWhere()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
using (var session = documentStore.OpenAsyncSession(dbname))
{
session.Store(entity);
yield return session.SaveChangesAsync();
}
using (var session = documentStore.OpenAsyncSession(dbname))
{
var query = session.Query<Company>()
.Where(x => x.Name == "Async Company #1")
.ToListAsync();
yield return query;
Assert.AreEqual(1, query.Result.Count);
Assert.AreEqual("Async Company #1", query.Result[0].Name);
}
}
}
示例6: When_Using_Sharded_Servers
public When_Using_Sharded_Servers()
{
server = "localhost";
port1 = 8079;
port2 = 8081;
path1 = GetPath("TestShardedDb1");
path2 = GetPath("TestShardedDb2");
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);
company1 = new Company { Name = "Company1" };
company2 = new Company { Name = "Company2" };
server1 = GetNewServer(port1, path1);
server2 = GetNewServer(port2, path2);
shards = new Shards {
new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1},
new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2}
};
shardSelection = MockRepository.GenerateStub<IShardSelectionStrategy>();
shardSelection.Stub(x => x.ShardIdForNewObject(company1)).Return("Shard1");
shardSelection.Stub(x => x.ShardIdForNewObject(company2)).Return("Shard2");
shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
shardStrategy = MockRepository.GenerateStub<IShardStrategy>();
shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection);
shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution);
}
示例7: CanGetTotalCount
public IEnumerable<Task> CanGetTotalCount()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
using (var session = documentStore.OpenAsyncSession(dbname))
{
session.Store(entity);
yield return session.SaveChangesAsync();
}
using (var session = documentStore.OpenAsyncSession(dbname))
{
RavenQueryStatistics stats;
var query = session.Query<Company>()
.Customize(x => x.WaitForNonStaleResults())
.Statistics(out stats)
.Where(x => x.Name == "Async Company #1")
.CountAsync();
yield return query;
Assert.AreEqual(1, query.Result);
}
}
}
示例8: CanInsertAsyncAndMultiGetAsync
public IEnumerable<Task> CanInsertAsyncAndMultiGetAsync()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
var entity1 = new Company {Name = "Async Company #1"};
var entity2 = new Company {Name = "Async Company #2"};
using (var session_for_storing = documentStore.OpenAsyncSession(dbname))
{
session_for_storing.Store(entity1);
session_for_storing.Store(entity2);
yield return session_for_storing.SaveChangesAsync();
}
using (var session_for_loading = documentStore.OpenAsyncSession(dbname))
{
var task = session_for_loading.LoadAsync<Company>(new[] {entity1.Id, entity2.Id});
yield return task;
Assert.AreEqual(entity1.Name, task.Result[0].Name);
Assert.AreEqual(entity2.Name, task.Result[1].Name);
}
}
}
示例9: WhenUsingShardedServers
public WhenUsingShardedServers()
{
const string server = "localhost";
const int port1 = 8079;
const int port2 = 8081;
company1 = new Company { Name = "Company1" };
company2 = new Company { Name = "Company2" };
server1 = GetNewServer(port1);
server2 = GetNewServer(port2);
shards = new List<IDocumentStore> {
new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1},
new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2}
}.ToDictionary(x => x.Identifier, x => x);
shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company1), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard1");
shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company2), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard2");
shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");
shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
}
示例10: WillGetNotificationWhenReadingNonAuthoritativeInformation
public void WillGetNotificationWhenReadingNonAuthoritativeInformation()
{
var company = new Company { Name = "Company Name" };
using (var session = documentStore.OpenSession())
{
using (var original = documentStore.OpenSession())
{
original.Store(company);
original.SaveChanges();
}
using (new TransactionScope())
{
session.Load<Company>(company.Id).Name = "Another Name";
session.SaveChanges();
using (new TransactionScope(TransactionScopeOption.Suppress))
{
using (var session2 = documentStore.OpenSession())
{
session2.Advanced.AllowNonAuthoritativeInformation = false;
session2.Advanced.NonAuthoritativeInformationTimeout = TimeSpan.Zero;
Assert.Throws<NonAuthoritativeInformationException>(() => session2.Load<Company>(company.Id));
}
}
}
}
}
示例11: WhenDocumentAlreadyExists_Can_Still_Generate_Values
public void WhenDocumentAlreadyExists_Can_Still_Generate_Values()
{
using (var store = NewDocumentStore())
{
var mk = new MultiTypeHiLoKeyGenerator(store, 5);
store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o);
using (var session = store.OpenSession())
{
var company = new Company();
session.Store(company);
var contact = new Contact();
session.Store(contact);
Assert.Equal("companies/1", company.Id);
Assert.Equal("contacts/1", contact.Id);
}
mk = new MultiTypeHiLoKeyGenerator(store, 5);
store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o);
using (var session = store.OpenSession())
{
var company = new Company();
session.Store(company);
var contact = new Contact();
session.Store(contact);
Assert.Equal("companies/6", company.Id);
Assert.Equal("contacts/6", contact.Id);
}
}
}
示例12: Should_insert_into_db_and_set_id
public void Should_insert_into_db_and_set_id()
{
using (var session = documentStore.OpenSession())
{
var entity = new Company {Name = "Company"};
session.Store(entity);
session.SaveChanges();
Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
}
}
示例13: Can_promote_transactions
public void Can_promote_transactions()
{
var process = Process.Start(GetRavenServerPath(), "--ram --set=Raven/Port==8079");
try
{
WaitForNetwork("http://localhost:8079");
var documentStore = new DocumentStore { Url = "http://localhost:8079" };
documentStore.Initialize();
var company = new Company { Name = "Company Name" };
var durableEnlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
using (var tx = new TransactionScope())
{
var session = documentStore.OpenSession();
session.Store(company);
session.SaveChanges();
Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
durableEnlistment, EnlistmentOptions.None);
Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
tx.Complete();
}
for (int i = 0; i < 15; i++)// wait for commit
{
using (var session2 = documentStore.OpenSession())
if (session2.Load<Company>(company.Id) != null)
break;
Thread.Sleep(100);
}
using (var session2 = documentStore.OpenSession())
Assert.NotNull((session2.Load<Company>(company.Id)));
for (int i = 0; i < 15; i++) // we have to wait to be notified, too
{
if(durableEnlistment.WasCommitted == false)
Thread.Sleep(100);
}
Assert.True(durableEnlistment.WasCommitted);
}
finally
{
process.Kill();
}
}
示例14: IdIsSetFromGeneratorOnStore
public void IdIsSetFromGeneratorOnStore()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenSession())
{
Company company = new Company();
session.Store(company);
Assert.Equal("companies/1", company.Id);
}
}
}
示例15: Should_insert_into_db_and_set_id
public void Should_insert_into_db_and_set_id()
{
using (var server = GetNewServer(port, path))
{
var documentStore = new DocumentStore { Url = "http://localhost:"+ port };
documentStore.Initialize();
var session = documentStore.OpenSession();
var entity = new Company {Name = "Company"};
session.Store(entity);
session.SaveChanges();
Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
}
}