Exemplo n.º 1
0
        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()));
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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");
            }
        }
Exemplo n.º 5
0
        public ActionResult _Search(string text)
        {
            var result = ExampleRepository.Filter(text);

            return(new JsonResult {
                Data = new SelectList(result, "Url", "Text")
            });
        }
Exemplo n.º 6
0
 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
            });
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
        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"
            });
        }
Exemplo n.º 12
0
        // 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 })
            });
        }
Exemplo n.º 13
0
        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");
        }
Exemplo n.º 14
0
        // 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 })
            }));
        }
Exemplo n.º 15
0
        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");
        }
Exemplo n.º 16
0
        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)));
        }
Exemplo n.º 17
0
        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");
        }
Exemplo n.º 18
0
        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.");
        }
Exemplo n.º 19
0
 public ExampleController(ExampleRepository exampleRepository)
 {
     this.exampleRepository = exampleRepository;
 }
Exemplo n.º 20
0
 public static string HelloWorld()
 {
     return(ExampleRepository.HelloWorld());
 }
Exemplo n.º 21
0
        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();
        }
Exemplo n.º 22
0
 public VocabularyTestController(WordRepository wordRepository, ExampleRepository exampleRepository)
 {
     this.wordRepository    = wordRepository;
     this.exampleRepository = exampleRepository;
 }
Exemplo n.º 23
0
 public ExampleController(ExampleRepository repo)
 {
     _repo = repo;
 }
Exemplo n.º 24
0
        public void CanCreateRepository()
        {
            var repository = ExampleRepository.InstantiateForMemory();

            Assert.IsNotNull(repository, "Repository shouldn't be null");
        }
Exemplo n.º 25
0
 public ExampleProcessor(ExampleRepository repostiory)
 {
     //Constructor is called on creation, do any dependency injection here
     _repository = repostiory;
 }
Exemplo n.º 26
0
 public ExampleController()
 {
     ExampleRepository = new ExampleRepository();
 }
Exemplo n.º 27
0
 public UnitOfWork(DemoContext context)
 {
     _context = context;
     Examples = new ExampleRepository(_context);
 }
Exemplo n.º 28
0
 public LoginController()
 {
     repository = new ExampleRepository();
 }
Exemplo n.º 29
0
 public ExampleService()
 {
     _context = new DataContext();
     _repo    = new ExampleRepository(_context);
 }