Example #1
0
        public void AddNotNullItems()
        {
            const string VALUE = "Hello";
            const string NAME  = "Joe";

            _dictionary.Add(VALUE, nameof(VALUE));
            Assert.Contains(_dictionary.ToDictionary(), kvp => kvp.Key == nameof(VALUE) && (string)kvp.Value == "Hello");

            _dictionary.Add(NAME, nameof(NAME), NAME);
            Assert.Contains(_dictionary.ToDictionary(), kvp => kvp.Key == nameof(NAME) && (string)kvp.Value == "Joe");
        }
        public void Should_return_dictionary_from_dynamic_dictionary()
        {
            //Given
            var input = new DynamicDictionary();

            //When
            var result = input.ToDictionary();

            //Then
            Assert.IsType(typeof(Dictionary <string, object>), result);
        }
        public void Should_return_dynamic_objects_as_objects()
        {
            //Given
            var input = new DynamicDictionary();

            input.Add("Test", new { Title = "Fred", Number = 123 });

            //When
            var result = input.ToDictionary();

            //Then
            Assert.Equal("Fred", ((dynamic)result["Test"]).Title);
            Assert.Equal(123, ((dynamic)result["Test"]).Number);
        }
Example #4
0
        public async Task <UserInfo> UpdateAdminUserAsync(string name = null, string displayName = null, string emailAddress = null)
        {
            var data = new DynamicDictionary
            {
                { name, "name" },
                { displayName, "displayName" },
                { emailAddress, "email" }
            };

            var response = await GetAdminUrl("/users")
                           .PutJsonAsync(data.ToDictionary())
                           .ConfigureAwait(false);

            return(await HandleResponseAsync <UserInfo>(response).ConfigureAwait(false));
        }
Example #5
0
        public async Task <bool> SaveAsync(DynamicDictionary dictionary, DynamicDictionarySaveMotive motive)
        {
            var connection = new SQLiteAsyncConnection(DataBasePath);
            await connection.CreateTableAsync <DynamicDictionaryStorageModel>();

            foreach (var pair in dictionary.ToDictionary())
            {
                var model = DynamicDictionaryStorageModel.Generate(pair.Key, pair.Value);

                if (await connection.Table <DynamicDictionaryStorageModel>().Where(z => z.Key == pair.Key).CountAsync() > 0)
                {
                    await connection.UpdateAsync(model);
                }
                else
                {
                    await connection.InsertAsync(model);
                }
            }

            return(true);
        }
Example #6
0
        public bool Save(DynamicDictionary dictionary, DynamicDictionarySaveMotive motive)
        {
            var connection = new SQLiteConnection(DataBasePath);

            connection.CreateTable <DynamicDictionaryStorageModel>();

            foreach (var pair in dictionary.ToDictionary())
            {
                var model = DynamicDictionaryStorageModel.Generate(pair.Key, pair.Value);

                if (connection.Table <DynamicDictionaryStorageModel>().Count(z => z.Key == pair.Key) > 0)
                {
                    connection.Update(model);
                }
                else
                {
                    connection.Insert(model);
                }
            }

            return(true);
        }
        public void Should_return_dynamic_objects_as_objects()
        {
            //Given
            var input = new DynamicDictionary();
            input.Add("Test", new { Title = "Fred", Number = 123 });

            //When
            var result = input.ToDictionary();

            //Then
            Assert.Equal("Fred", ((dynamic)result["Test"]).Title);
            Assert.Equal(123, ((dynamic)result["Test"]).Number);
        }
        public void Should_return_dictionary_from_dynamic_dictionary()
        {
            //Given
            var input = new DynamicDictionary();

            //When
            var result = input.ToDictionary();

            //Then
            Assert.IsType(typeof(Dictionary<string, object>), result);
        }
Example #9
0
 public IndexModel(DynamicDictionary query) : base()
 {
     Query = query.ToDictionary();
 }
Example #10
0
        public SyncModule(IAuthenticationProvider authenticationProvider, ISyncStore store, IReflectionStore reflectionStore, ILogStore log)
            : base(authenticationProvider, "/sync")
        {
            this.Post["/"] = parameters =>
            {
                try
                {
                    var user = this.CurrentUser;
                    var dto  = this.Bind <SynchronizationDto>();

                    var sync = store.Add(dto);
                    return(this.Response.AsJson(sync));
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Get["/"] = parameters =>
            {
                try
                {
                    var user = this.CurrentUser;
                    DynamicDictionary           q       = this.Request.Query;
                    Dictionary <string, string> filters = q.ToDictionary().ToDictionary(t => t.Key, t => t.Value.ToString());

                    var result = store.GetAll(filters);

                    return(this.Response.AsJson(result));
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Get["/{id}"] = parameters =>
            {
                try
                {
                    var    user = this.CurrentUser;
                    string id   = parameters.id;
                    var    dto  = store.GetById(id);

                    return(this.Response.AsJson(dto));
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Get["/{id}/reflections"] = parameters =>
            {
                try
                {
                    var    user   = this.CurrentUser;
                    string syncId = parameters.id;
                    var    sync   = store.GetById(syncId);
                    int    take;
                    var    reflections = Int32.TryParse(this.Request.Query["take"].ToString(), out take)
                                              ? reflectionStore.GetBySynchronization(sync, take)
                                              : reflectionStore.GetBySynchronization(sync);

                    return(this.Response.AsJson(reflections));
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Put["/{id}/status"] = parameters =>
            {
                try
                {
                    var user = this.CurrentUser;
                    var dto  = this.Bind <UpdateStatusDto>();

                    if (dto != null && dto.Status.HasValue)
                    {
                        try
                        {
                            string id = parameters.id;
                            store.UpdateStatus(id, dto.Status.Value);
                            return(HttpStatusCode.OK);
                        }
                        catch (StatusNotChangedException)
                        {
                            return(this.Negotiate
                                   .WithReasonPhrase(ReasonPhrases.StatusAlreadyUpdated)
                                   .WithStatusCode(HttpStatusCode.Conflict));
                        }
                    }

                    else
                    {
                        return(this.Negotiate
                               .WithReasonPhrase(ReasonPhrases.UpdateStatusBadRequest)
                               .WithStatusCode(HttpStatusCode.BadRequest));
                    }
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Put["{id}/logs"] = parameters =>
            {
                try
                {
                    var user = this.CurrentUser;
                    var dto  = this.Bind <SyncLogDto>();

                    if (dto != null && !string.IsNullOrEmpty(dto.Text))
                    {
                        try
                        {
                            string syncId = parameters.id;
                            var    sync   = store.GetById(syncId);
                            log.LogSync(sync, dto.Text);
                            return(HttpStatusCode.OK);
                        }
                        catch (StatusNotChangedException)
                        {
                            return(this.Negotiate
                                   .WithReasonPhrase("Log bad request.")
                                   .WithStatusCode(HttpStatusCode.BadRequest));
                        }
                    }
                    else
                    {
                        return(this.Negotiate
                               .WithReasonPhrase("Log bad request.")
                               .WithStatusCode(HttpStatusCode.BadRequest));
                    }
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };

            this.Get["{id}/logs"] = parameters =>
            {
                try
                {
                    var user = this.CurrentUser;
                    try
                    {
                        string syncId = parameters.id;
                        var    sync   = store.GetById(syncId);

                        if (sync == null)
                        {
                            return(this.Negotiate
                                   .WithReasonPhrase("Sync not found.")
                                   .WithStatusCode(HttpStatusCode.NotFound));
                        }

                        var l = log.Get(sync);

                        if (l == null)
                        {
                            return(this.Negotiate
                                   .WithReasonPhrase("Log not found.")
                                   .WithStatusCode(HttpStatusCode.NotFound));
                        }

                        return(this.Response.AsJson(l));
                    }
                    catch (StatusNotChangedException)
                    {
                        return(this.Negotiate
                               .WithReasonPhrase("Log bad request.")
                               .WithStatusCode(HttpStatusCode.BadRequest));
                    }
                }
                catch (Exception e)
                {
                    return(this.ResponseFromException(e));
                }
            };
        }