public static string HelloWorld() { var scry = new ScryfallRepository(); scry.GetCards(); return(ExampleRepository.HelloWorld()); }
// // GET: /Home/ public ActionResult Index() { // Create our example repository. var repository = new ExampleRepository(); return(View(repository.LoadModel())); }
public async Task <Result <UnitResult, Error> > Handle(AddNewExampleCommand request, CancellationToken cancellationToken) { var student = CurrentContextProvider.CurrentUser() as Student; if (student == null) { return(Result.Failure <UnitResult, Error>(Error.AuthorizationError("The current user is not a student"))); } if (request.Text.IsNullOrEmpty()) { return(Result.Failure <UnitResult, Error>( Error.ValidationError("The text has an invalid value for the example"))); } var result = HskLevel.FromText(request.HskLevel); if (result.IsFailure) { return(Result.Failure <UnitResult, Error>(Error.ValidationError(result.Error))); } await ExampleRepository.AddAsync(new Example(request.Text, HskLevel.FromText(request.HskLevel).Value, student)); return(new UnitResult()); }
public void CanCreateSubItemsDuringCreate() { var repository = ExampleRepository.InstantiateForMemory(); var o = new ExampleBase { Description = "Test Base" }; o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub A" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub B" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub C" }); var result = repository.Create(o); Assert.IsTrue(result, "Create should return true"); Assert.AreEqual(3, o.SubObjects.Count, "Sub object count should be three"); foreach (var sub in o.SubObjects) { Assert.IsTrue(sub.Id > 0, "Sub object " + sub.Name + " should have and ID > 0"); Assert.IsTrue(sub.BaseId == o.bvin, "Sub object " + sub.Name + " should have received base bvin"); Assert.IsTrue(sub.SortOrder > 0, "Sub object " + sub.Name + " should have sort order > 0"); } }
public ActionResult _Search(string text) { var result = ExampleRepository.Filter(text); return(new JsonResult { Data = new SelectList(result, "Url", "Text") }); }
public async Task TestSleep() { var options = new DbContextOptionsBuilder <ExampleContext>() .UseInMemoryDatabase("example") .Options; var context = new ExampleContext(options); var repo = new ExampleRepository(context); await repo.CountEntities(); }
public IHttpActionResult AnotherExampleGet(int id) { var model = ExampleRepository.GetData(); return(ExampleReturn("body", "v1")); //return BadRequest(); //return NotFound(); //return Ok(model); }
public ExampleRepositoryTests() { var contextOptions = new DbContextOptionsBuilder <TemplateContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; _context = new TemplateContext(contextOptions); _exampleRepository = new ExampleRepository(_context); }
public ExampleApiModel AnotherGet(int id) { var model = ExampleRepository.GetData(); return(new ExampleApiModel() { Id = model.Id, Data = model.Data }); }
static void Main(string[] args) { IWordRespository wordRepo = new WordRespository(); IDetailRepository detailRepo = new DetailRepository(); IExampleRepository exampleRepo = new ExampleRepository(); ISynonymRepository synonymRepo = new SynonymRepository(); ISubsenseRepository subsenseRepo = new SubsenseRepository(); Scraper obj = new Scraper(wordRepo, detailRepo, exampleRepo, synonymRepo, subsenseRepo); obj.ScrapeAll(); }
static void Main(string[] args) { var ContextFactory = new ContextFactory(); DbFactory dbFactory = new DbFactory(ContextFactory.CreateDbContext()); ExampleRepository exampleRepository = new ExampleRepository(dbFactory); exampleRepository.Insert(new Lambda.Domain.Example { Name = "Hola" }); }
// GET api/values/5 - GetData public ExampleApiModel Get(int id) { var model = ExampleRepository.GetData(); var urlHelper = new UrlHelper(Request); //CreateLink(_urlHelper.Link("Example", new {id = 1}), "self"); //CreateLink(_urlHelper.Link("Example", new {id = 2}), "next"); return(new ExampleApiModel() { Id = model.Id, Data = model.Data, Url = urlHelper.Link("Example", new { id }) }); }
public void CanCreateObjectInRepository() { var repository = ExampleRepository.InstantiateForMemory(); var o = new ExampleBase { LastUpdatedUtc = new DateTime(2001, 1, 1), Description = "This is an example base", IsActive = true }; Assert.IsTrue(repository.Create(o), "Create should be true"); Assert.AreNotEqual(string.Empty, o.bvin, "Bvin should not be empty"); Assert.AreEqual(DateTime.UtcNow.Year, o.LastUpdatedUtc.Year, "Last updated date should match current year"); }
// GET api/values/5 - GetData public HttpResponseMessage Get(int id) { var model = ExampleRepository.GetData(); var urlHelper = new UrlHelper(Request); var username = _identityService.GetUser(); if (username == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, new ExampleApiModel { Id = model.Id, Data = username, Url = urlHelper.Link("Example", new { id }) })); }
public void CanMergeSubItems() { var repository = ExampleRepository.InstantiateForMemory(); // Create Basic Sample var o = new ExampleBase { Description = "Test Base" }; o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub A" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub B" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub C" }); var result = repository.Create(o); var existing = repository.Find(o.bvin); Assert.AreEqual(o.SubObjects.Count, existing.SubObjects.Count, "Sub object count should be equal"); Assert.AreEqual(o.SubObjects[0].Name, existing.SubObjects[0].Name, "First item name should be equal"); existing.SubObjects.Add(new ExampleSubObject { Name = "New Sub A" }); // index 3, then 2 existing.SubObjects.Add(new ExampleSubObject { Name = "New Sub B" }); // index 4, then 3 existing.SubObjects[0].Name = "Updated Sub A"; existing.SubObjects.RemoveAt(2); Assert.IsTrue(repository.Update(existing), "update should be true"); var target = repository.Find(o.bvin); Assert.IsNotNull(target, "target should not be null"); Assert.AreEqual(4, target.SubObjects.Count, "Sub object count should be four after merge"); Assert.AreEqual("Updated Sub A", target.SubObjects[0].Name, "First sub name didn't match"); Assert.AreEqual("Test Sub B", target.SubObjects[1].Name, "Second name didn't match"); Assert.AreEqual("New Sub A", target.SubObjects[2].Name, "Third name didn't match"); Assert.AreEqual("New Sub B", target.SubObjects[3].Name, "Fourth Name didn't match"); }
public void ExampleRepository_WhenCalled_InsertsAObjectOnDatabase() { // Arrange // Arrange var testObject = new ExampleClass(); var context = new Mock <DbContext>(); var dbSetMock = new Mock <DbSet <ExampleClass> >(); context.Setup(x => x.Set <ExampleClass>()).Returns(dbSetMock.Object); dbSetMock.Setup(x => x.Add(It.IsAny <ExampleClass>())).Returns(testObject); // Act var repository = new ExampleRepository(context.Object); repository.Inserir(testObject); //Assert context.Verify(x => x.Set <ExampleClass>()); dbSetMock.Verify(x => x.Add(It.Is <ExampleClass>(y => y == testObject))); }
public void CanFindObjectInRepositoryAfterCreate() { var repository = ExampleRepository.InstantiateForMemory(); var o = new ExampleBase { LastUpdatedUtc = new DateTime(2001, 1, 1), Description = "This is an example base", IsActive = true }; repository.Create(o); var targetId = o.bvin; var found = repository.Find(targetId); Assert.IsNotNull(found, "Found item should not be null"); Assert.AreEqual(o.bvin, found.bvin, "Bvin should match"); Assert.AreEqual(o.Description, found.Description, "Bvin should match"); Assert.AreEqual(o.IsActive, found.IsActive, "IsActive should match"); Assert.AreEqual(o.LastUpdatedUtc.Ticks, found.LastUpdatedUtc.Ticks, "Last Updated should match"); Assert.AreEqual(o.SubObjects.Count, found.SubObjects.Count, "Sub object count should match"); }
public void CanDeleteSubsOnDelete() { var repository = ExampleRepository.InstantiateForMemory(); // Create Basic Sample var o = new ExampleBase { Description = "Test Base" }; o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub A" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub B" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub C" }); var result = repository.Create(o); var existing = repository.Find(o.bvin); Assert.AreEqual(o.SubObjects.Count, existing.SubObjects.Count, "Sub object count should be equal"); Assert.AreEqual(o.SubObjects[0].Name, existing.SubObjects[0].Name, "First item name should be equal"); Assert.IsTrue(repository.Delete(o.bvin)); var target = repository.Find(o.bvin); Assert.IsNull(target, "target should not null after delete"); var subs = repository.PeakIntoSubObjects(o.bvin); Assert.IsNotNull(subs, "Sub list should NOT be null but should be empty."); Assert.AreEqual(0, subs.Count, "Sub list should be empty."); }
public ExampleController(ExampleRepository exampleRepository) { this.exampleRepository = exampleRepository; }
public static string HelloWorld() { return(ExampleRepository.HelloWorld()); }
static void Main(string[] args) { var fakeRepository = new ExampleRepository(); var smoulderFactory = new SmoulderFactory(); //Object oriented methodology var firstSmoulder = smoulderFactory.Build(new ExampleLoader(), new ExampleProcessor(fakeRepository), new ExampleDistributor(), 50000); //Run Demo with first Smoulder RunDemo(firstSmoulder); //Functional methodology //Create second smoulder by passing methods to factory, thus removing the requirement to instantiate any worker units var secondSmoulder = smoulderFactory.Build <ProcessDataObject, DistributeDataObject>(null, null, null, 50000) .SetLoaderAction(token => { var rng = new Random(); var data = new ProcessDataObject { DataValue = rng.Next() }; Thread.Sleep(rng.Next(1, 50)); return(data); }) .SetProcessorAction((data, token) => { fakeRepository.SaveData(data); var result = new DistributeDataObject { DataValue1 = data.DataValue, DataValue2 = data.DataValue / 2 }; Random rng = new Random(); Thread.Sleep(rng.Next(1, 100)); return(result); }) .SetDistributorAction((data, token) => { Random rng = new Random(); Thread.Sleep(rng.Next(1, 25)); }) .SetLoaderOnError(e => throw new Exception("Throw loader exception with inner exception attached", e)) .SetProcessorOnError(e => throw new Exception("Throw processor exception with inner exception attached", e)) .SetDistributorOnError(e => throw new Exception("Throw distributor exception with inner exception attached", e)); //Run Demo with second Smoulder RunDemo(secondSmoulder); //Object oriented methodology with some functional stuff to save having to create oversimple worker units //Create third smoulder by mixing the two previous methods var thirdSmoulder = smoulderFactory.Build(new ExampleLoader(), new ExampleProcessor(fakeRepository), null, 50000) .SetDistributorAction((data, token) => { Random rng = new Random(); Thread.Sleep(rng.Next(1, 25)); }); //Run Demo with third Smoulder RunDemo(thirdSmoulder); Console.WriteLine("Press enter to finish the Smoulder demonstration process"); Console.ReadLine(); }
public VocabularyTestController(WordRepository wordRepository, ExampleRepository exampleRepository) { this.wordRepository = wordRepository; this.exampleRepository = exampleRepository; }
public ExampleController(ExampleRepository repo) { _repo = repo; }
public void CanCreateRepository() { var repository = ExampleRepository.InstantiateForMemory(); Assert.IsNotNull(repository, "Repository shouldn't be null"); }
public ExampleProcessor(ExampleRepository repostiory) { //Constructor is called on creation, do any dependency injection here _repository = repostiory; }
public ExampleController() { ExampleRepository = new ExampleRepository(); }
public UnitOfWork(DemoContext context) { _context = context; Examples = new ExampleRepository(_context); }
public LoginController() { repository = new ExampleRepository(); }
public ExampleService() { _context = new DataContext(); _repo = new ExampleRepository(_context); }