Ejemplo n.º 1
0
        public async Task UpdateDocumentTest()
        {
            var serializer = new JsonSerializer();
            var @ref = Path.Combine(REF, "updateTest");
            IRepository repo = new EmbeddedRepository(serializer);
            var docCollection = await repo.InitCollection<Person>(@ref);
            var newName = Guid.NewGuid().ToString();

            var expectedDoc = docCollection.New();
            expectedDoc.Data.Salary = _person.Salary;
            expectedDoc.Data.FullName = _person.FullName;
            await expectedDoc.Save();
            await expectedDoc.SyncUpdate(_ => _.FullName = newName);

            // exists in docCollection
            var actualFromColl = docCollection.Documents
                .Where(_ => _.Data.FullName == expectedDoc.Data.FullName && _.Data.Salary == expectedDoc.Data.Salary)
                .FirstOrDefault();

            // exists on disk
            DirectoryInfo dirInfo = new DirectoryInfo(@ref);
            var actualFile = dirInfo.GetFiles("*.json").OrderBy(_ => _.CreationTime).LastOrDefault();
            var actualPerson = File.ReadAllText(actualFile.FullName);
            var actualFromDisk = serializer.Deserialize<Person>(actualPerson);

            // Assert
            Assert.Equal(expectedDoc.Data.Salary, actualFromColl.Data.Salary);
            Assert.Equal(expectedDoc.Data.FullName, actualFromColl.Data.FullName);

            Assert.Equal(expectedDoc.Data.Salary, actualFromDisk.Salary);
            Assert.Equal(expectedDoc.Data.FullName, actualFromDisk.FullName);
        }
Ejemplo n.º 2
0
        public async Task DeleteDocumentTest()
        {
            var serializer = new JsonSerializer();
            var @ref = Path.Combine(REF, "deleteTest");
            IRepository repo = new EmbeddedRepository(serializer);
            var docCollection = await repo.InitCollection<Person>(@ref);

            var expectedDoc = docCollection.New();
            expectedDoc.Data.Salary = _person.Salary;
            expectedDoc.Data.FullName = _person.FullName;
            await expectedDoc.Save();

            await expectedDoc.Delete();

            var actualFromColl = docCollection.Documents
                .Where(_ => _.Data.FullName == expectedDoc.Data.FullName && _.Data.Salary == expectedDoc.Data.Salary)
                .FirstOrDefault();

            DirectoryInfo dirInfo = new DirectoryInfo(@ref);
            var actualFile = dirInfo.GetFiles("*.json").OrderBy(_ => _.CreationTime).LastOrDefault();

            // Assert
            Assert.Null(actualFromColl);
            Assert.Null(actualFile);
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            IRepository repository = new EmbeddedRepository(new JsonSerializer());
            var         task       = repository.Init <User>("UserData.Json");

            task.Wait();
            var doc = task.Result;
            var s   = string.Empty;

            SaveAction(doc).Wait();
            LoadAction(doc);

            while (true)
            {
                Console.WriteLine("Type 'edit' or 'delete'");
                s = Console.ReadLine();
                if (s == "edit")
                {
                    SaveAction(doc).Wait();
                    LoadAction(doc);
                }

                if (s == "delete")
                {
                    DeleteAction(doc).Wait();
                    SaveAction(doc).Wait();
                    LoadAction(doc);
                }
            }
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            IRepository repository = new EmbeddedRepository(new JsonSerializer());
            var         users      = repository.InitCollection <User>("UsersData");

            users.Wait();
            services.AddSingleton(users.Result);
            services.AddMvc();
            services.AddApplicationInsightsTelemetry(Configuration);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var repository = new EmbeddedRepository(new JsonSerializer());
            var sitemaps   = repository.InitCollection <SiteMap>("../data/sitemaps");

            sitemaps.Wait();

            services.AddSingleton(sitemaps.Result);
            services.AddSession();
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();
        }
Ejemplo n.º 6
0
        public async Task UpdateDocumentTest2()
        {
            var serializer = new JsonSerializer();
            var @ref = Path.Combine(REF, "updateTest2");
            IRepository repo = new EmbeddedRepository(serializer);
            var docCollection = await repo.InitCollection<Person>(@ref);
            var newName = Guid.NewGuid().ToString();

            var doc = docCollection.New(_person);
            await doc.Save();

            Assert.Equal(doc.Data.Salary, _person.Salary);
            Assert.Equal(doc.Data.FullName, _person.FullName);

            var newPerson = new Person { FullName = newName };
            await doc.SyncUpdate(newPerson);

            // Assert
            Assert.Equal(doc.Data.Salary, 0);
            Assert.Equal(doc.Data.FullName, newName);
        }