public AnswerRepositoryTests() { _dataContext = new FakeDataContext(); _fakeAnswers = _dataContext.EntitySet <Answer>() as FakeAnswers; _repository = new AnswerRepository(_dataContext); }
private CategoryProvider CreateProvider(FakeDataContext context = null) { context = context ?? CreateDataContext(); var repository = new CommonRepository(context); return(new CategoryProvider(repository)); }
private string GetTemporalTableSqlDependingOnIfTableIsTemporalOrNot <TEntity>( ITableHelper <FakeDataContext> tableHelper, params Type[] entityTypesToCreateTemporalTablesFor) where TEntity : class { var options = DbContextOptionsSetup.Setup <FakeDataContext>(); using (var context = new FakeDataContext(options)) { // Register entity types to support temporal tables. entityTypesToCreateTemporalTablesFor ?.ToList() ?.ForEach(e => TemporalEntitiesCache.Add(context.Model.FindEntityType(e))); var entityType = context.Model.FindEntityType(typeof(TEntity)); var temporalTableSqlBuilder = new TemporalTableSqlBuilder <FakeDataContext>( context, new TemporalTableSqlGeneratorFactory(), tableHelper); string sql = temporalTableSqlBuilder.BuildTemporalTablesSqlForEntityTypes(new[] { entityType }); return(sql); } }
public void Clear_MultipleDataSets_ShouldDisposeAndClearAllInternalContexts( Mock<BaseDataSet<int>> dataSet1, Mock<BaseDataSet<string>> dataSet2, FakeDataContext context) { // Arrange context.SetUpDataSet(dataSet1.Object); context.Set<int>(); context.SetUpDataSet(dataSet2.Object); context.Set<string>(); var internalContext = (IDictionary<string, IBaseDataSet>)typeof(BaseDataContext).GetField("_internalContext", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(context); if (internalContext == null) throw new Exception("Cannot get the value of _internalContext."); internalContext.Count.Should().Be(2); // Act context.Clear(); // Assert internalContext.Count.Should().Be(0); dataSet1.Verify(s => s.Dispose(), Times.Once); dataSet2.Verify(s => s.Dispose(), Times.Once); }
public async Task Order_Index() { // arrange var fakeDb = new FakeDataContext(); var fakeModel = new OrdersModel(fakeDb.Orders.ToList(), "bob", new DateTimeOffset(), new DateTimeOffset(), null, false); var fakeOrdersQuery = new Mock <IOrdersQuery>(); fakeOrdersQuery.Setup(o => o.IndexHelperAsync("bob", null, null, null, false)) .ReturnsAsync(fakeModel); var fakeTelemetryProvider = new Mock <ITelemetryProvider>(); OrdersController controller = GetOrdersController(fakeOrdersQuery, fakeTelemetryProvider); // act var resultTask = await controller.Index(null, null, null); var viewResult = resultTask as ViewResult; // assert Assert.IsNotNull(viewResult); fakeOrdersQuery.Verify(o => o.IndexHelperAsync("bob", null, null, null, false), Times.Once, "IndexHelperAsync not called correctly"); var model = viewResult.Model as OrdersModel; Assert.IsNotNull(model); Assert.AreSame(model, fakeModel); }
public static UserManager <ApplicationUser> GetTestUserManager() { var dataContext = new FakeDataContext(); var userManager = new UserManager <ApplicationUser>(dataContext, null, null, null, null, null, null, null, null); return(userManager); }
public AnswerDescriptionRepositoryTests() { _dataContext = new FakeDataContext(); _fakeAnswerDescriptions = _dataContext.EntitySet <AnswerDescription>() as FakeAnswerDescriptions; _repository = new AnswerDescriptionRepository(_dataContext); }
public TestSetup() { var dataContext = new FakeDataContext(); AnswerVotesRepository = new Repository <AnswerVote>(dataContext); AnswerDescriptionVoteRepository = new Repository <AnswerDescriptionVote>(dataContext); CacheMock = new TestCacheManager().CacheMock; AnswerDescriptionServiceMock = new Mock <IAnswerDescriptionService>(); // Suppose we always adding answer 15 AnswerDescriptionServiceMock.Setup( x => x.FindByAnswerDescriptionId(It.IsAny <int>()) ).Returns(new AnswerDescriptionDto() { AnswerId = 15 }); TestLoggerFactory = new TestLoggerFactory(); VoteService = new VoteService( AnswerDescriptionServiceMock.Object, CacheMock.Object, AnswerVotesRepository, AnswerDescriptionVoteRepository, TestLoggerFactory); }
public TestSetup() { var dataContext = new FakeDataContext(); ResourceStringsRepository = new Repository <ResourceString>(dataContext); CacheMock = new TestCacheManager().CacheMock; ResourcesService = new ResourcesService(CacheMock.Object, ResourceStringsRepository); TestLoggerFactory = null; }
// public FakeSuggestions FakeSuggestions; public TestSetup() { var dataContext = new FakeDataContext(); Repository = new Repository <SearchEntry>(dataContext); TestLoggerFactory = new TestLoggerFactory(); SearchEntryService = new SearchEntryService(Repository, TestLoggerFactory); // FakeSuggestions = dataContext.EntitySet<Suggestion>() as FakeSuggestions; }
public TestSetup() { var dataContext = new FakeDataContext(); BadWordsRepository = new Repository <BadWord>(dataContext); CacheMock = new TestCacheManager().CacheMock; ResourcesServiceMock = new Mock <IResourcesService>(); ResourcesServiceMock.Setup(x => x.GetString(It.IsAny <string>(), It.IsAny <string>())).Returns(ANY_RESOURCE_STRING); ProfanityService = new ProfanityService(CacheMock.Object, BadWordsRepository, ResourcesServiceMock.Object); }
public TestSetup() { var dataContext = new FakeDataContext(); Repository = new Repository <Suggestion>(dataContext); CacheMock = new TestCacheManager().CacheMock; TestLoggerFactory = new TestLoggerFactory(); SuggestionService = new SuggestionService(CacheMock.Object, Repository, TestLoggerFactory); FakeSuggestions = dataContext.EntitySet <Suggestion>() as FakeSuggestions; }
public NomenclatureViewModel() { this._Nomenclatures = new ObservableCollection <NomenclatureHedar>(FakeDataContext.GetAllNomenclatures()); this._NomenclatureFields = new ObservableCollection <NomeclatureMetaData>(FakeDataContext.GetNomenlatureFields(1)); this._Fields = new ObservableCollection <ObservableCollection <string> >(); var list = FakeDataContext.GetNomenclatureContent(1); foreach (var li in list) { var ader = new ObservableCollection <string>(li); _Fields.Add(ader); } }
public static Models.Color Create(FakeDataContext context, byte id = 4, string name = "Chestnut") { Setup(context); var color = new Models.Color { Id = id, Name = name }; context.Colors.Add(color); return(color); }
public static Models.Horse Create(FakeDataContext context, int id = 1, string name = "Man o' War") { _context = context; Setup(context); var horse = new Models.Horse { Id = id, Name = name }; context.Horses.Add(horse); return(horse); }
public void AddTemporalTableTest() { var options = DbContextOptionsSetup.Setup <FakeDataContext>(); using (var context = new FakeDataContext(options)) { var entityType = context.Model.FindEntityType(typeof(User)); // Add entity type. TemporalEntitiesCache.Add(entityType); // Test if the entity type exists in the cache. Assert.IsTrue(TemporalEntitiesCache.IsEntityConfigurationTemporal(entityType)); } }
public void FakeDataContextTests_IUserStore_Implemented() { var context = new FakeDataContext(); Assert.ThrowsAny <NotImplementedException>(() => context.GetUserIdAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.GetUserNameAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.SetUserNameAsync(null, null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.GetNormalizedUserNameAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.SetNormalizedUserNameAsync(null, null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.CreateAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.UpdateAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.DeleteAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.FindByIdAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.FindByNameAsync(null, new CancellationToken())); Assert.ThrowsAny <NotImplementedException>(() => context.Dispose()); var task = context.SaveChangesAsync(); task.Wait(); Assert.Equal(task.Result, 0); }
private FakeDataContext CreateDataContext() { var context = new FakeDataContext(); var product1 = new Good { Id = product_1, Name = "Product1", Description = "Product one" }; var product2 = new Good { Id = product_2, Name = "Product2", Description = "Product two", }; var category1 = new EntityCategory { Id = category_1, Name = "Category1", Description = "Category one" }; var reference = new CategoryGoodReference { Id = Guid.NewGuid(), Category = category1, Good = product1 }; context.SetCollectionAsDbSet(new List <Good> { product1, product2 }); context.SetCollectionAsDbSet(new List <EntityCategory> { category1 }); context.SetCollectionAsDbSet(new List <CategoryGoodReference> { reference }); return(context); }
private FakeDataContext CreateDataContext() { var context = new FakeDataContext(); var category1 = new EntityCategory { Id = category_1, Name = "Category1", Description = "Category one" }; var category2 = new EntityCategory { Id = category_2, Name = "Category2", Description = "Category two" }; context.SetCollectionAsDbSet(new List <EntityCategory> { category1, category2 }); return(context); }
public void Rollback_MultipleDataSets_ShouldRollbackAllInternalContexts( Mock<BaseDataSet<int>> dataSet1, Mock<BaseDataSet<string>> dataSet2, FakeDataContext context) { // Arrange context.SetUpDataSet(dataSet1.Object); context.Set<int>(); context.SetUpDataSet(dataSet2.Object); context.Set<string>(); // Act context.Rollback(); // Assert dataSet1.Verify(s => s.Rollback(), Times.Once); dataSet2.Verify(s => s.Rollback(), Times.Once); }
public ContoView() { InitializeComponent(); DataContext = vm; var AllAccounts = new ObservableCollection <AccountsModel>(FakeDataContext.GetAllAccounts().Where(e => e.FirmaId == ConfigTempoSinglenton.GetInstance().CurrentFirma.Id)); List <string> test = new List <string>(); foreach (var item in AllAccounts) { test.Add(item.ToString()); } kreditsmetka.AutoCompleteManager.DataProvider = new SimpleStaticDataProvider(test); //kreditsmetka.AutoCompleteManager.AutoAppend = true; debitsmetka.AutoCompleteManager.DataProvider = new SimpleStaticDataProvider(test); //debitsmetka.AutoCompleteManager.AutoAppend = true; //List<string> test = new List<string>(); //foreach (var item in vm.Cities) //{ // test.Add(item.Name); //} //city.AutoCompleteManager.DataProvider=new SimpleStaticDataProvider(test); }
private static void Setup(FakeDataContext context) { context.Horses = context.Horses ?? new List <Models.Horse>(); }
private static void Setup(FakeDataContext context) { context.Colors = context.Colors ?? new List <Models.Color>(); }
public void Save <T>(T list) { FakeDataContext.Save <T>(list);//fix }
public void Set_DataSetAlreadyExistsInInternalContext_ShouldReturnSameInstance( FakeDataContext context) { // Act var dataSet1 = context.Set<object>(); var dataSet2 = context.Set<object>(); // Assert dataSet1.Should().Be.EqualTo(dataSet2); }
public void VoteController_VoteAnswer_AddsVote() { const string USER_NAME = "asd"; // Arrange var dataContext = new FakeDataContext(); var testLoggerFactory = new TestLoggerFactory(); var userManager = new UserManager <ApplicationUser>(dataContext, null, null, null, null, null, null, null, null); var identity = new GenericIdentity(USER_NAME); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "ASD")); var principal = new GenericPrincipal(identity, null); var httpContext = new DefaultHttpContext() { User = principal }; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var userDto = new ApplicationUserDto() { UserName = USER_NAME }; // Setup test data // var vote = new AnswerVoteDto() { AnswerId = 1 }; // Setup user service var userServiceMock = new Mock <IUserService>(); userServiceMock.Setup(x => x.FindByUserName(It.IsAny <string>())).Returns(userDto); // Setup vote service var voteServiceMock = new Mock <IVoteService>(); voteServiceMock.Setup(x => x.VoteAnswer(It.IsAny <AnswerVoteDto>())).Returns( new DataOperationResult() { IsNew = true } ); // Setup resource service var resourceServiceMock = new Mock <IResourcesService>(); resourceServiceMock.Setup(x => x.GetString(It.IsAny <string>(), It.IsAny <string>())).Returns("A"); // Setup statistics service var staticticsServiceMock = new Mock <IStatisticsService>(); staticticsServiceMock.Setup(x => x.LoadUserStatictics(It.IsAny <ApplicationUserDto>())); var controller = new VoteController(userServiceMock.Object, voteServiceMock.Object, resourceServiceMock.Object, testLoggerFactory, staticticsServiceMock.Object) { ControllerContext = controllerContext }; // Act // var result = controller.VoteAnswer(vote.AnswerId); var result = controller.VoteAnswer(1); // Assert var viewResult = Assert.IsType <RedirectToActionResult>(result); // Controller did call the vote service voteServiceMock.Verify(x => x.VoteAnswer(It.IsAny <AnswerVoteDto>()), Times.Once()); // Controller did call the resource service resourceServiceMock.Verify(x => x.GetString(BaseApiController.DEFAULT_CULTURE, Lines.THANK_YOU_FOR_VOTING), Times.Once()); }
public NomenWizardViewModel() { _NomenclatureWizardModel = new NomenclatureWizardModel(new List <Tempo2012.EntityFramework.Models.LookUpMetaData>(FakeDataContext.GetAllNomenclatureFields())); this.CurrentPage = this.Pages[0]; }
public TestSetup() { var dataContext = new FakeDataContext(); AnswerRepository = new Repository <Answer>(dataContext); }
public void TestInitialize() { fakeDataContext = new FakeDataContext(); }
public NomenclatureAddStep2ViewModel() : base(null) { this._NomenclatureFields = new ObservableCollection <NomeclatureMetaData>(FakeDataContext.GetAllNomenclatureFields()); this._NomenclatureFieldsSelected = new ObservableCollection <NomeclatureMetaData>(); }
public RepositoryTests() { _dataContext = new FakeDataContext(); _repository = new Repository <Answer>(_dataContext); }
private void MoveAllLeft() { NomenclatureFields = new ObservableCollection <NomeclatureMetaData>(FakeDataContext.GetAllNomenclatureFields()); NomenclatureFieldsSelected = new ObservableCollection <NomeclatureMetaData>(); OnPropertyChanged("NomenclatureFieldsSelected"); OnPropertyChanged("NomenclatureFields"); }
public void Setup() { _personService = new PersonService(FakeDataContext.CreateContextWithTestData()); }
public Users GetUser(string username, string password) { return(FakeDataContext.GetAllUsers().FirstOrDefault(e => e.Username == username && e.PassWord == password));//to do }
public void SaveChanges_MultipleDataSets_ShouldCommitAllInternalContexts( Mock<BaseDataSet<int>> dataSet1, Mock<BaseDataSet<string>> dataSet2, FakeDataContext context) { // Arrange context.SetUpDataSet(dataSet1.Object); context.Set<int>(); context.SetUpDataSet(dataSet2.Object); context.Set<string>(); // Act context.SaveChanges(); // Assert dataSet1.Verify(s => s.Commit(), Times.Once); dataSet2.Verify(s => s.Commit(), Times.Once); }