本文整理汇总了C#中EarlyLearningCenter类的典型用法代码示例。如果您正苦于以下问题:C# EarlyLearningCenter类的具体用法?C# EarlyLearningCenter怎么用?C# EarlyLearningCenter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EarlyLearningCenter类属于命名空间,在下文中一共展示了EarlyLearningCenter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_attach_parent_with_child_collection
public void Can_attach_parent_with_child_collection()
{
using (var context = new EarlyLearningCenter())
{
var category = new Category
{
Id = 1,
Products = new List<Product>
{
new Product { Id = 1 },
new Product { Id = 2 },
new Product { Id = 3 }
}
};
context.ChangeTracker.TrackGraph(category, e => e.State = EntityState.Modified);
Assert.Equal(4, context.ChangeTracker.Entries().Count());
Assert.Equal(EntityState.Modified, context.Entry(category).State);
Assert.Equal(EntityState.Modified, context.Entry(category.Products[0]).State);
Assert.Equal(EntityState.Modified, context.Entry(category.Products[1]).State);
Assert.Equal(EntityState.Modified, context.Entry(category.Products[2]).State);
Assert.Same(category, category.Products[0].Category);
Assert.Same(category, category.Products[1].Category);
Assert.Same(category, category.Products[2].Category);
Assert.Equal(category.Id, category.Products[0].CategoryId);
Assert.Equal(category.Id, category.Products[1].CategoryId);
Assert.Equal(category.Id, category.Products[2].CategoryId);
}
}
示例2: Members_check_arguments
public void Members_check_arguments()
{
using (var context = new EarlyLearningCenter())
{
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => context.Add<Random>(null)).ParamName);
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.ThrowsAsync<ArgumentNullException>(() => context.AddAsync<Random>(null)).Result.ParamName);
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(
() => context.AddAsync<Random>(null, new CancellationToken()).GetAwaiter().GetResult()).ParamName);
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => context.Update<Random>(null)).ParamName);
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.ThrowsAsync<ArgumentNullException>(() => context.UpdateAsync<Random>(null)).Result.ParamName);
Assert.Equal(
"entity",
// ReSharper disable once AssignNullToNotNullAttribute
Assert.ThrowsAsync<ArgumentNullException>(() => context.UpdateAsync<Random>(null, new CancellationToken())).Result.ParamName);
}
}
示例3: Can_get_Context
public void Can_get_Context()
{
using (var context = new EarlyLearningCenter())
{
Assert.Same(context, context.ChangeTracker.Context);
}
}
示例4: Can_get_state_manager
public void Can_get_state_manager()
{
using (var context = new EarlyLearningCenter())
{
var stateManger = ((IAccessor<IServiceProvider>)context).Service.GetRequiredService<IStateManager>();
Assert.Same(stateManger, ((IAccessor<IStateManager>)context.ChangeTracker).Service);
}
}
示例5: Can_get_state_manager
public void Can_get_state_manager()
{
using (var context = new EarlyLearningCenter())
{
var stateManger = context.GetService<IStateManager>();
Assert.Same(stateManger, context.ChangeTracker.GetInfrastructure());
}
}
示例6: Can_get_all_entries
public void Can_get_all_entries()
{
using (var context = new EarlyLearningCenter())
{
var category = context.Add(new Category()).Entity;
var product = context.Add(new Product()).Entity;
Assert.Equal(
new object[] { category, product },
context.ChangeTracker.Entries().Select(e => e.Entity).OrderBy(e => e.GetType().Name));
}
}
示例7: Each_context_gets_new_scoped_services
public void Each_context_gets_new_scoped_services()
{
var serviceProvider = TestHelpers.Instance.CreateServiceProvider();
IServiceProvider contextServices;
using (var context = new EarlyLearningCenter(serviceProvider))
{
contextServices = ((IInfrastructure<IServiceProvider>)context).Instance;
Assert.Same(contextServices, ((IInfrastructure<IServiceProvider>)context).Instance);
}
using (var context = new EarlyLearningCenter(serviceProvider))
{
Assert.NotSame(contextServices, ((IInfrastructure<IServiceProvider>)context).Instance);
}
}
示例8: TrackEntitiesTest
private static void TrackEntitiesTest(
Func<DbSet<Category>, Category, EntityEntry<Category>> categoryAdder,
Func<DbSet<Product>, Product, EntityEntry<Product>> productAdder, EntityState expectedState)
{
using (var context = new EarlyLearningCenter())
{
var category1 = new Category { Id = 1, Name = "Beverages" };
var category2 = new Category { Id = 2, Name = "Foods" };
var product1 = new Product { Id = 1, Name = "Marmite", Price = 7.99m };
var product2 = new Product { Id = 2, Name = "Bovril", Price = 4.99m };
var categoryEntry1 = categoryAdder(context.Categories, category1);
var categoryEntry2 = categoryAdder(context.Categories, category2);
var productEntry1 = productAdder(context.Products, product1);
var productEntry2 = productAdder(context.Products, product2);
Assert.Same(category1, categoryEntry1.Entity);
Assert.Same(category2, categoryEntry2.Entity);
Assert.Same(product1, productEntry1.Entity);
Assert.Same(product2, productEntry2.Entity);
Assert.Same(category1, categoryEntry1.Entity);
Assert.Equal(expectedState, categoryEntry2.State);
Assert.Same(category2, categoryEntry2.Entity);
Assert.Equal(expectedState, categoryEntry2.State);
Assert.Same(product1, productEntry1.Entity);
Assert.Equal(expectedState, productEntry1.State);
Assert.Same(product2, productEntry2.Entity);
Assert.Equal(expectedState, productEntry2.State);
Assert.Same(categoryEntry1.GetInfrastructure(), context.Entry(category1).GetInfrastructure());
Assert.Same(categoryEntry2.GetInfrastructure(), context.Entry(category2).GetInfrastructure());
Assert.Same(productEntry1.GetInfrastructure(), context.Entry(product1).GetInfrastructure());
Assert.Same(productEntry2.GetInfrastructure(), context.Entry(product2).GetInfrastructure());
}
}
示例9: Can_get_singleton_service_from_scoped_configuration
public void Can_get_singleton_service_from_scoped_configuration()
{
using (var context = new EarlyLearningCenter())
{
Assert.IsType<StateManager>(context.GetService<IStateManager>());
}
}
示例10: Entry_methods_delegate_to_underlying_state_manager
public void Entry_methods_delegate_to_underlying_state_manager()
{
var entity = new Random();
var stateManagerMock = new Mock<IStateManager>();
var entry = CreateInternalEntryMock().Object;
stateManagerMock.Setup(m => m.GetOrCreateEntry(entity)).Returns(entry);
var services = new ServiceCollection()
.AddScoped(_ => stateManagerMock.Object);
var serviceProvider = TestHelpers.Instance.CreateServiceProvider(services);
using (var context = new EarlyLearningCenter(serviceProvider))
{
Assert.Same(entry, context.Entry(entity).GetInfrastructure());
Assert.Same(entry, context.Entry((object)entity).GetInfrastructure());
}
}
示例11: It_throws_with_derived_name
public void It_throws_with_derived_name()
{
var context = new EarlyLearningCenter();
context.Dispose();
var ex = Assert.Throws<ObjectDisposedException>(() => context.Model);
Assert.Contains(nameof(EarlyLearningCenter), ex.Message);
}
示例12: Replaced_services_are_scoped_appropriately
public void Replaced_services_are_scoped_appropriately()
{
var services = new ServiceCollection();
services
.AddEntityFramework()
.GetInfrastructure()
.AddSingleton<IModelSource, FakeModelSource>()
.AddScoped<IStateManager, FakeStateManager>();
var provider = services.BuildServiceProvider();
var context = new EarlyLearningCenter(provider);
var modelSource = context.GetService<IModelSource>();
context.Dispose();
context = new EarlyLearningCenter(provider);
var stateManager = context.GetService<IStateManager>();
Assert.Same(stateManager, context.GetService<IStateManager>());
Assert.Same(modelSource, context.GetService<IModelSource>());
context.Dispose();
context = new EarlyLearningCenter(provider);
Assert.NotSame(stateManager, context.GetService<IStateManager>());
Assert.Same(modelSource, context.GetService<IModelSource>());
context.Dispose();
}
示例13: Can_get_replaced_singleton_service_from_scoped_configuration
public void Can_get_replaced_singleton_service_from_scoped_configuration()
{
var provider = new ServiceCollection()
.AddEntityFramework()
.GetInfrastructure()
.AddSingleton<IEntityMaterializerSource, FakeEntityMaterializerSource>()
.BuildServiceProvider();
using (var context = new EarlyLearningCenter(provider))
{
Assert.IsType<FakeEntityMaterializerSource>(context.GetService<IEntityMaterializerSource>());
}
}
示例14: SaveChangesAsync_only_passes_dirty_entries_to_Database
public async Task SaveChangesAsync_only_passes_dirty_entries_to_Database()
{
var passedEntries = new List<IUpdateEntry>();
var database = new Mock<IDatabase>();
database.Setup(s => s.SaveChangesAsync(It.IsAny<IReadOnlyList<IUpdateEntry>>(), It.IsAny<CancellationToken>()))
.Callback<IEnumerable<IUpdateEntry>, CancellationToken>((e, c) => passedEntries.AddRange(e))
.Returns(Task.FromResult(3));
var valueGenMock = new Mock<IValueGeneratorSelector>();
valueGenMock.Setup(m => m.Select(It.IsAny<IProperty>(), It.IsAny<IEntityType>())).Returns(Mock.Of<ValueGenerator>());
var servicesMock = new Mock<IDatabaseProviderServices>();
servicesMock.Setup(m => m.Database).Returns(database.Object);
servicesMock.Setup(m => m.ValueGeneratorSelector).Returns(valueGenMock.Object);
servicesMock.Setup(m => m.ModelSource).Returns(new Mock<ModelSource>(new DbSetFinder(), new CoreConventionSetBuilder())
{ CallBase = true }.Object);
servicesMock
.Setup(m => m.ModelValidator)
.Returns(new LoggingModelValidator(new Logger<LoggingModelValidator>(new LoggerFactory())));
var sourceMock = new Mock<IDatabaseProvider>();
sourceMock.Setup(m => m.IsConfigured(It.IsAny<IDbContextOptions>())).Returns(true);
sourceMock.Setup(m => m.GetProviderServices(It.IsAny<IServiceProvider>())).Returns(servicesMock.Object);
var services = new ServiceCollection();
services.AddEntityFramework();
services.AddInstance(sourceMock.Object);
var serviceProvider = services.BuildServiceProvider();
using (var context = new EarlyLearningCenter(serviceProvider, new DbContextOptionsBuilder().Options))
{
context.Entry(new Category { Id = 1 }).State = EntityState.Unchanged;
context.Entry(new Category { Id = 2 }).State = EntityState.Modified;
context.Entry(new Category { Id = 3 }).State = EntityState.Added;
context.Entry(new Category { Id = 4 }).State = EntityState.Deleted;
Assert.Equal(4, context.ChangeTracker.Entries().Count());
await context.SaveChangesAsync();
}
Assert.Equal(3, passedEntries.Count);
database.Verify(
s => s.SaveChangesAsync(It.IsAny<IReadOnlyList<InternalEntityEntry>>(), It.IsAny<CancellationToken>()),
Times.Once);
}
示例15: Can_set_known_context_scoped_services_using_type_activation
public void Can_set_known_context_scoped_services_using_type_activation()
{
var services = new ServiceCollection()
.AddScoped<IStateManager, FakeStateManager>();
var provider = TestHelpers.Instance.CreateServiceProvider(services);
using (var context = new EarlyLearningCenter(provider))
{
Assert.IsType<FakeStateManager>(context.GetService<IStateManager>());
}
}