Exemple #1
0
        void excluding_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30 });

                act = () => gemini = gemini.Exclude("Interest");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30 });

                act = () => gemini = gemini.Exclude("inTerest");

                it["casing doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Amount")).should_be(true);
                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };
        }
Exemple #2
0
 static DeferredFailedValidation()
 {
     Gemini.Initialized <DeferredFailedValidation>(d =>
     {
         d.Extend <Validations>();
     });
 }
Exemple #3
0
        void describe_casing()
        {
            before = () =>
            {
                objectToConvert = new Gemini(
                    new
                {
                    Id    = 15,
                    Name  = "Mirror's Edge",
                    Owner = new Gemini(new
                    {
                        Id     = 22,
                        Handle = "@amirrajan"
                    })
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert, new NoCasingChange());
            };

            it["serializes with altered casing"] = () =>
            {
                var expected = @"{ ""Id"": 15, ""Name"": ""Mirror's Edge"", ""Owner"": { ""Id"": 22, ""Handle"": ""@amirrajan"" } }";

                jsonString.should_be(expected);
            };
        }
Exemple #4
0
 static FailedValidation()
 {
     Gemini.Initialized <FailedValidation>(d =>
     {
         d.Extend <Validations>();
     });
 }
Exemple #5
0
        void describe_casing()
        {
            before = () =>
            {
                objectToConvert = new Gemini(
                new
                {
                    Id = 15,
                    Name = "Mirror's Edge",
                    Owner = new Gemini(new
                    {
                        Id = 22,
                        Handle = "@amirrajan"
                    })
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert, new NoCasingChange());
            };

            it["serializes with altered casing"] = () =>
            {
                var expected = @"{ ""Id"": 15, ""Name"": ""Mirror's Edge"", ""Owner"": { ""Id"": 22, ""Handle"": ""@amirrajan"" } }";

                jsonString.should_be(expected);
            };
        }
Exemple #6
0
        void excluding_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30 });

                act = () => gemini = gemini.Exclude("Interest");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30 });

                act = () => gemini = gemini.Exclude("inTerest");

                it["casing doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Amount")).should_be(true);
                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };
        }
        void describe_collections_that_have_collections()
        {
            before = () =>
            {
                dynamic person1 = new Gemini(new { Name = "Jane Doe", Friends = new List <string> {
                                                       "A", "B", "C"
                                                   } });

                objectToConvert = new List <dynamic> {
                    person1
                };
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["serializes the list for both"] = () =>
            {
                var expected = @"[ { ""name"": ""Jane Doe"", ""friends"": [ ""A"", ""B"", ""C"" ] } ]";

                jsonString.should_be(expected);
            };
        }
        void describe_gemini_to_json()
        {
            before = () =>
            {
                objectToConvert = new Gemini(new
                {
                    Id       = 15,
                    String   = "hello",
                    Char     = 'a',
                    DateTime = DateTime.Today,
                    Double   = (double)100,
                    Guid     = Guid.Empty,
                    Decimal  = (decimal)15,
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["converts gemini"] = () =>
            {
                string expected = @"{{ ""id"": {0}, ""string"": ""{1}"", ""char"": ""{2}"", ""dateTime"": ""{3}"", ""double"": {4}, ""guid"": ""{5}"", ""decimal"": {6} }}"
                                  .With(15, "hello", 'a', DateTime.Today, (double)100, Guid.Empty, (decimal)15);

                jsonString.should_be(expected);
            };
        }
        void converting_nested_object()
        {
            before = () =>
            {
                objectToConvert = new Gemini(
                    new
                {
                    Id    = 15,
                    Name  = "Mirror's Edge",
                    Owner = new Gemini(new
                    {
                        Id     = 22,
                        Handle = "@amirrajan"
                    })
                });
            };

            act = () => jsonString = DynamicToJson.Convert(objectToConvert);

            it["converts whole object graph"] = () =>
            {
                string expected = @"{ ""id"": 15, ""name"": ""Mirror's Edge"", ""owner"": { ""id"": 22, ""handle"": ""@amirrajan"" } }";

                jsonString.should_be(expected);
            };
        }
Exemple #10
0
        public static dynamic RecordToGemini(this IDataReader rdr, Func <dynamic, dynamic> projection)
        {
            dynamic e = new Gemini();
            var     d = e.Prototype as IDictionary <string, object>;

            for (int i = 0; i < rdr.FieldCount; i++)
            {
                d.Add(rdr.GetName(i), DBNull.Value.Equals(rdr[i]) ? null : rdr[i]);
            }
            return(projection(e));
        }
        void describe_db_rows_to_json()
        {
            before = () =>
            {
                Seed seed = new Seed();

                seed.PurgeDb();

                seed.CreateTable("Rabbits", seed.Id(), new { Name = "nvarchar(255)" }).ExecuteNonQuery();

                seed.CreateTable("Tasks",
                                 seed.Id(),
                                 new { Description = "nvarchar(255)" },
                                 new { RabbitId = "int" },
                                 new { DueDate = "datetime" }).ExecuteNonQuery();

                var rabbitId = new { Name = "Yours Truly" }.InsertInto("Rabbits");

                new { rabbitId, Description = "bolt onto vans", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                rabbitId = new { Name = "Hiro Protaganist" }.InsertInto("Rabbits");

                new { rabbitId, Description = "save the world", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                new { rabbitId, Description = "deliver pizza", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                rabbitId = new { Name = "Lots" }.InsertInto("Rabbits");

                for (int i = 0; i < 10; i++)
                {
                    new
                    {
                        rabbitId,
                        Description = "Task: " + i.ToString(),
                        DueDate     = new DateTime(2013, 1, 14)
                    }.InsertInto("Tasks");
                }
            };

            it["disregards self referencing objects"] = () =>
            {
                var results = tasks.All().Include("Rabbits").ToList();

                (results as IEnumerable <dynamic>).ForEach(s =>
                {
                    s.Rabbit = s.Rabbit();
                });

                objectToConvert = new Gemini(new { Tasks = results });
                string expected = @"{ ""tasks"": [ { ""id"": 1, ""description"": ""bolt onto vans"", ""rabbitId"": 1, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 1, ""name"": ""Yours Truly"" } }, { ""id"": 2, ""description"": ""save the world"", ""rabbitId"": 2, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 2, ""name"": ""Hiro Protaganist"" } }, { ""id"": 3, ""description"": ""deliver pizza"", ""rabbitId"": 2, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 2, ""name"": ""Hiro Protaganist"" } }, { ""id"": 4, ""description"": ""Task: 0"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 5, ""description"": ""Task: 1"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 6, ""description"": ""Task: 2"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 7, ""description"": ""Task: 3"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 8, ""description"": ""Task: 4"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 9, ""description"": ""Task: 5"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 10, ""description"": ""Task: 6"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 11, ""description"": ""Task: 7"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 12, ""description"": ""Task: 8"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 13, ""description"": ""Task: 9"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } } ] }";
                jsonString = DynamicToJson.Convert(objectToConvert);
                jsonString.should_be(expected);
            };
        }
        static describe_LibraryController()
        {
            Gemini.Initialized<Email>(e =>
            {
                e.Send = new DynamicMethod(() =>
                {
                    emailsSent.Add(e);

                    return null;
                });
            });
        }
Exemple #13
0
        void specify_a_class_can_be_extended_globally()
        {
            dynamic personToExtend = new PersonToExtend();

            ((bool)personToExtend.RespondsTo("Changes")).should_be_false();

            Gemini.Extend <PersonToExtend, Changes>();

            personToExtend = new PersonToExtend();

            ((bool)personToExtend.RespondsTo("Changes")).should_be_true();
        }
        void change_tracking_can_be_added_directly_to_gemini()
        {
            before = () =>
            {
                gemini = new Gemini(new { FirstName = "Amir" });

                new Changes(gemini);
            };

            it["change tracking methods exist when changes is mixed in"] = () =>
                ((bool)gemini.HasChanged()).should_be(false);
        }
Exemple #15
0
        void change_tracking_can_be_added_directly_to_gemini()
        {
            before = () =>
            {
                gemini = new Gemini(new { FirstName = "Amir" });

                new Changes(gemini);
            };

            it["change tracking methods exist when changes is mixed in"] = () =>
                                                                           ((bool)gemini.HasChanged()).should_be(false);
        }
Exemple #16
0
        void when_setting_property_of_gemini()
        {
            it["sets property on underlying prototype"] = () =>
            {
                gemini.Title = "Some other name";
                (blog.Title as string).should_be("Some other name");
            };

            it["sets property of underlying prototype even if property's first letter doesn't match case"] = () =>
            {
                gemini.title = "Some other name";
                (blog.Title as string).should_be("Some other name");
            };

            it["sets property of underlying prototype even if property's first letter is capitalized, but underlying property is lowercase"] = () =>
            {
                gemini.Body = "Some other name";
                (blog.body as string).should_be("Some other name");
            };

            it["ignores case for geminied entity"] = () =>
            {
                gemini.bodysummary = "Blog Summary New";
                (blog.BodySummary as string).should_be("Blog Summary New");
            };

            it["sets property to a new value if the property doesn't exist"] = () =>
            {
                gemini.FooBar = "Foobar";

                (blog.FooBar as string).should_be("Foobar");
            };

            it["reference to self are added as methods"] = () =>
            {
                dynamic self = new Gemini(new { FirstName = "Amir", LastName = "Rajan" });

                self.Self = self;

                (self.Self() as object).should_be(self as object);
            };

            it["references to self where prototypes match are added as methods"] = () =>
            {
                dynamic self = new Gemini(new { FirstName = "Amir", LastName = "Rajan" });

                dynamic samePrototype = new Gemini(self);

                self.Self = samePrototype;

                (self.Self() as object).should_be(samePrototype as object);
            };
        }
        void specify_permitted_parameters_are_allowed_to_be_set_view_mass_assignment()
        {
            dynamic foobar = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            foobar.Extend<StrongParameters>();

            foobar.Permit("FirstName", "LastName");

            foobar.SetMembers(new { FirstName = "First", LastName = "Last" });

            (foobar.FirstName as string).should_be("First");

            (foobar.LastName as string).should_be("Last");
        }
Exemple #18
0
        void specify_permitted_parameters_are_allowed_to_be_set_view_mass_assignment()
        {
            dynamic foobar = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            foobar.Extend <StrongParameters>();

            foobar.Permit("FirstName", "LastName");

            foobar.SetMembers(new { FirstName = "First", LastName = "Last" });

            (foobar.FirstName as string).should_be("First");

            (foobar.LastName as string).should_be("Last");
        }
            static Comment()
            {
                Gemini.Initialized <Comment>(i =>
                {
                    i.Associates = new DynamicFunction(() =>
                    {
                        return(new[]
                        {
                            new BelongsTo(i.Blogs)
                        });
                    });

                    new Associations(i);
                });
            }
Exemple #20
0
 public static dynamic RecordToGemini(this IDataReader rdr, Func <dynamic, dynamic> projection)
 {
     if (projection == null)
     {
         var e = new Prototype() as IDictionary <string, object>;;
         PopluateDynamicDictionary(rdr, e);
         return(e);
     }
     else
     {
         dynamic e = new Gemini();
         PopluateDynamicDictionary(rdr, e.Prototype);
         return(projection(e));
     }
 }
Exemple #21
0
        void specify_exception_is_thrown_if_mass_assignment_is_performed_on_non_permitted_parameters()
        {
            dynamic foobar = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            foobar.Extend <StrongParameters>();

            foobar.Permit("FirstName");

            try
            {
                foobar.SetMembers(new { FirstName = "First", LastName = "Last" });

                throw new Exception("Exception was not thrown");
            }
            catch (InvalidOperationException ex)
            {
            }
        }
        void specify_exception_is_thrown_if_mass_assignment_is_performed_on_non_permitted_parameters()
        {
            dynamic foobar = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            foobar.Extend<StrongParameters>();

            foobar.Permit("FirstName");

            try
            {
                foobar.SetMembers(new { FirstName = "First", LastName = "Last" });

                throw new Exception("Exception was not thrown");
            }
            catch (InvalidOperationException)
            {
                
            }
        }
        void describe_two_objects_referencing_the_same_list()
        {
            before = () =>
            {
                dynamic person1 = new Gemini(new { Name = "Jane Doe" });

                dynamic person2 = new Gemini(new { Name = "John Doe" });

                dynamic person3 = new Gemini(new { Name = "Jane Smith" });

                var friends = new List <dynamic>
                {
                    new Gemini(new { Name = "John Smith", Friends = new List <dynamic> {
                                         person1, person2, person3
                                     } })
                };

                person1.Friends = friends;

                person2.Friends = friends;

                objectToConvert = new Gemini(new
                {
                    People = new List <dynamic>()
                    {
                        person1,
                        person2
                    }
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["serializes the list for both"] = () =>
            {
                var expected = @"{ ""people"": [ { ""name"": ""Jane Doe"", ""friends"": [ { ""name"": ""John Smith"", ""friends"": [ { ""name"": ""Jane Smith"" } ] } ] }, { ""name"": ""John Doe"", ""friends"": [ { ""name"": ""John Smith"", ""friends"": [ { ""name"": ""Jane Smith"" } ] } ] } ] }";

                jsonString.should_be(expected);
            };
        }
        void describe_two_objects_referencing_the_same_list()
        {
            before = () =>
            {
                dynamic person1 = new Gemini(new { Name = "Jane Doe" });

                dynamic person2 = new Gemini(new { Name = "John Doe" });

                dynamic person3 = new Gemini(new { Name = "Jane Smith" });

                var friends = new List<dynamic>
                {
                    new Gemini(new { Name = "John Smith", Friends = new List<dynamic> { person1, person2, person3 } })
                };

                person1.Friends = friends;

                person2.Friends = friends;

                objectToConvert = new Gemini(new
                {
                    People = new List<dynamic>() 
                    {
                        person1,
                        person2
                    }
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["serializes the list for both"] = () =>
            {
                var expected = @"{ ""people"": [ { ""name"": ""Jane Doe"", ""friends"": [ { ""name"": ""John Smith"", ""friends"": [ { ""name"": ""Jane Smith"" } ] } ] }, { ""name"": ""John Doe"", ""friends"": [ { ""name"": ""John Smith"", ""friends"": [ { ""name"": ""Jane Smith"" } ] } ] } ] }";

                jsonString.should_be(expected);
            };
        }
Exemple #25
0
        void specify_circular_references()
        {
            dynamic otherFriend = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            dynamic friend = new Gemini(new { FirstName = "John", LastName = "Doe", Friend = otherFriend });

            otherFriend.Friend = friend;

            var info = friend.__Info__() as string;

            info.should_be(@"this (Gemini)
  FirstName (String): John
  LastName (String): Doe
  Friend (Gemini)
    FirstName (String): Jane
    LastName (String): Doe
    SetMembers (DynamicFunctionWithParam)
    Friend (circular)
  SetMembers (DynamicFunctionWithParam)
");
        }
Exemple #26
0
        void specify_circular_references()
        {
            dynamic otherFriend = new Gemini(new { FirstName = "Jane", LastName = "Doe" });

            dynamic friend = new Gemini(new { FirstName = "John", LastName = "Doe", Friend = otherFriend });

            otherFriend.Friend = friend;

            var info = friend.__Info__() as string;

            info.should_be(@"this (Gemini)
  FirstName (String): John
  LastName (String): Doe
  Friend (Gemini)
    FirstName (String): Jane
    LastName (String): Doe
    SetMembers (DynamicFunctionWithParam)
    Friend (circular)
  SetMembers (DynamicFunctionWithParam)
");
        }
        void describe_collections_that_have_collections()
        {
            before = () =>
            {
                dynamic person1 = new Gemini(new { Name = "Jane Doe", Friends = new List<string> { "A", "B", "C" } });

                objectToConvert = new List<dynamic> { person1 };
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["serializes the list for both"] = () =>
            {
                var expected = @"[ { ""name"": ""Jane Doe"", ""friends"": [ ""A"", ""B"", ""C"" ] } ]";

                jsonString.should_be(expected);
            };
        }
Exemple #28
0
        void selecting_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () => gemini = gemini.Select("Term", "Amount");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () =>
                {
                    gemini = gemini.Select("term", "aMount", "dueDate");
                };

                it["case doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("DueDate")).should_be(true);
                };
            };
        }
Exemple #29
0
        void selecting_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () => gemini = gemini.Select("Term", "Amount");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () =>
                {
                    gemini = gemini.Select("term", "aMount", "dueDate");
                };

                it["case doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("DueDate")).should_be(true);
                };
            };
        }
Exemple #30
0
        public ActionResult Get(int gameId)
        {
            var game = games.Single(gameId);

            dynamic gameResult = new Gemini(game);

            gameResult.Player1Squares = game.SquaresFor(game.Player1Id);

            gameResult.Player2Squares = game.SquaresFor(game.Player2Id);

            gameResult.Player2HitsOnPlayer1 = game.HitsOn(game.Player1Id);

            gameResult.Player2MissesOnPlayer1 = game.MissesOn(game.Player1Id);

            gameResult.Player1HitsOnPlayer2 = game.HitsOn(game.Player2Id);

            gameResult.Player1MissesOnPlayer2 = game.MissesOn(game.Player2Id);

            gameResult.Started = game.Started();

            gameResult.Loser = game.Loser();

            return(new DynamicJsonResult(gameResult));
        }
Exemple #31
0
        public static void Mixins()
        {
            Gemini.Extend <DynamicModels>(d =>
            {
                d.Exclude = new DynamicFunctionWithParam(excludeList =>
                {
                    var list = excludeList as IEnumerable <dynamic>;

                    var result = new List <dynamic>();

                    foreach (var item in d)
                    {
                        if (list.Any(s => s.Id == item.Id))
                        {
                            continue;
                        }

                        result.Add(item);
                    }

                    return(new DynamicModels(result));
                });
            });
        }
Exemple #32
0
        void describe_gemini_to_json()
        {
            before = () =>
            {
                objectToConvert = new Gemini(new
                {
                    Id = 15,
                    String = "hello",
                    Char = 'a',
                    DateTime = DateTime.Today,
                    Double = (double)100,
                    Guid = Guid.Empty,
                    Decimal = (decimal)15,
                });
            };

            act = () =>
            {
                jsonString = DynamicToJson.Convert(objectToConvert);
            };

            it["converts gemini"] = () =>
            {
                string expected = @"{{ ""id"": {0}, ""string"": ""{1}"", ""char"": ""{2}"", ""dateTime"": ""{3}"", ""double"": {4}, ""guid"": ""{5}"", ""decimal"": {6} }}"
                                    .With(15, "hello", 'a', DateTime.Today, (double)100, Guid.Empty, (decimal)15);

                jsonString.should_be(expected);
            };
        }
Exemple #33
0
 void specify_initializing_gemini_with_null_does_not_throw_error()
 {
     gemini = new Gemini(null);
 }
Exemple #34
0
 void specify_initializing_gemini_with_null_does_not_throw_error()
 {
     gemini = new Gemini(null);
 }
Exemple #35
0
        public void NavigateGeminiScheme(string fullQuery, System.Windows.Navigation.NavigatingCancelEventArgs e, SiteIdentity siteIdentity, bool requireSecure = true)
        {
            var geminiUri = e.Uri.OriginalString;

            var sessionPath = Session.Instance.SessionPath;
            var appDir      = AppDomain.CurrentDomain.BaseDirectory;

            var settings = new UserSettings();

            var hash = HashService.GetMd5Hash(fullQuery);

            //uses .txt as extension so content loaded as text/plain not interpreted by the browser
            //if user requests a view-source.
            var rawFile  = sessionPath + "\\" + hash + ".txt";
            var gmiFile  = sessionPath + "\\" + hash + ".gmi";
            var htmlFile = sessionPath + "\\" + hash + ".htm";

            //delete txt file as GemGet seems to sometimes overwrite not create afresh
            File.Delete(rawFile);
            File.Delete(gmiFile);

            //delete any existing html file to encourage webbrowser to reload it
            File.Delete(htmlFile);

            var uri = new Uri(fullQuery);
            //use a proxy for any other scheme that is not gemini
            var proxy           = ""; //use none
            var connectInsecure = false;

            X509Certificate2 certificate;

            certificate = Session.Instance.CertificatesManager.GetCertificate(uri.Host);   //may be null if none assigned or available



            if (uri.Scheme != "gemini")
            {
                proxy = settings.HttpSchemeProxy;
            }

            try
            {
                GeminiResponse geminiResponse;
                try
                {
                    geminiResponse = (GeminiResponse)Gemini.Fetch(uri, certificate, proxy, connectInsecure, settings.MaxDownloadSizeMb * 1024, settings.MaxDownloadTimeSeconds);
                }
                catch (Exception err)
                {
                    //warn, but continue if there are server validation errors
                    //in these early days of Gemini we dont forbid visiting a site with an expired cert or mismatched host name
                    //but we do give a warning each time
                    if (err.Message == "The remote certificate was rejected by the provided RemoteCertificateValidationCallback.")
                    {
                        mMainWindow.ToastNotify("Note: the certificate from: " + e.Uri.Authority + " is expired or invalid.", ToastMessageStyles.Warning);

                        //try again insecure this time
                        geminiResponse = (GeminiResponse)Gemini.Fetch(uri, certificate, proxy, true, settings.MaxDownloadSizeMb * 1024, settings.MaxDownloadTimeSeconds);
                    }
                    else
                    {
                        //reraise
                        throw;
                    }
                }

                if (geminiResponse.codeMajor == '1')
                {
                    //needs input, then refetch

                    mMainWindow.ToggleContainerControlsForBrowser(true);

                    NavigateGeminiWithInput(e, geminiResponse);
                }

                else if (geminiResponse.codeMajor == '2')
                {
                    //success
                    File.WriteAllBytes(rawFile, geminiResponse.bytes.ToArray());


                    if (File.Exists(rawFile))
                    {
                        if (geminiResponse.meta.Contains("text/gemini"))
                        {
                            File.Copy(rawFile, gmiFile);
                        }
                        else if (geminiResponse.meta.Contains("text/html"))
                        {
                            //is an html file served over gemini - probably not common, but not unheard of
                            var htmltoGmiResult = ConverterService.HtmlToGmi(rawFile, gmiFile);

                            if (htmltoGmiResult.Item1 != 0)
                            {
                                mMainWindow.ToastNotify("Could not convert HTML to GMI: " + fullQuery, ToastMessageStyles.Error);
                                mMainWindow.ToggleContainerControlsForBrowser(true);
                                e.Cancel = true;
                                return;
                            }
                        }
                        else if (geminiResponse.meta.Contains("text/"))
                        {
                            //convert plain text to a gemini version (wraps it in a preformatted section)
                            var textToGmiResult = ConverterService.TextToGmi(rawFile, gmiFile);

                            if (textToGmiResult.Item1 != 0)
                            {
                                mMainWindow.ToastNotify("Could not render text as GMI: " + fullQuery, ToastMessageStyles.Error);
                                mMainWindow.ToggleContainerControlsForBrowser(true);
                                e.Cancel = true;
                                return;
                            }
                        }
                        else
                        {
                            //a download
                            //its an image - rename the raw file and just show it
                            var pathFragment = (new UriBuilder(fullQuery)).Path;
                            var ext          = Path.GetExtension(pathFragment);

                            var binFile = rawFile + (ext == "" ? ".tmp" : ext);
                            File.Copy(rawFile, binFile, true); //rename overwriting

                            if (geminiResponse.meta.Contains("image/"))
                            {
                                mMainWindow.ShowImage(fullQuery, binFile, e);
                            }
                            else
                            {
                                SaveFileDialog saveFileDialog = new SaveFileDialog();

                                saveFileDialog.FileName = Path.GetFileName(pathFragment);

                                if (saveFileDialog.ShowDialog() == true)
                                {
                                    try
                                    {
                                        //save the file
                                        var savePath = saveFileDialog.FileName;

                                        File.Copy(binFile, savePath, true); //rename overwriting

                                        mMainWindow.ToastNotify("File saved to " + savePath, ToastMessageStyles.Success);
                                    }
                                    catch (SystemException err)
                                    {
                                        mMainWindow.ToastNotify("Could not save the file due to: " + err.Message, ToastMessageStyles.Error);
                                    }
                                }

                                mMainWindow.ToggleContainerControlsForBrowser(true);
                                e.Cancel = true;
                            }

                            return;
                        }

                        if (geminiResponse.uri.ToString() != fullQuery)
                        {
                            string redirectUri = fullQuery;

                            if (geminiResponse.uri.ToString().Contains("://"))
                            {
                                //a full url
                                //normalise the URi (e.g. remove default port if specified)
                                redirectUri = UriTester.NormaliseUri(new Uri(geminiResponse.uri.ToString())).ToString();
                            }
                            else
                            {
                                //a relative one
                                var baseUri   = new Uri(fullQuery);
                                var targetUri = new Uri(baseUri, geminiResponse.uri.ToString());
                                redirectUri = UriTester.NormaliseUri(targetUri).ToString();
                            }

                            var finalUri = new Uri(redirectUri);

                            if (e.Uri.Scheme == "gemini" && finalUri.Scheme != "gemini")
                            {
                                //cross-scheme redirect, not supported
                                mMainWindow.ToastNotify("Cross scheme redirect from Gemini not supported: " + redirectUri, ToastMessageStyles.Warning);
                                mMainWindow.ToggleContainerControlsForBrowser(true);
                                e.Cancel = true;
                                return;
                            }
                            else
                            {
                                //others e.g. http->https redirect are fine
                            }

                            //redirected to a full gemini url
                            geminiUri = redirectUri;

                            //regenerate the hashes using the redirected target url
                            hash = HashService.GetMd5Hash(geminiUri);

                            var gmiFileNew  = sessionPath + "\\" + hash + ".txt";
                            var htmlFileNew = sessionPath + "\\" + hash + ".htm";

                            //move the source file
                            try
                            {
                                if (File.Exists(gmiFileNew))
                                {
                                    File.Delete(gmiFileNew);
                                }
                                File.Move(gmiFile, gmiFileNew);
                            }
                            catch (Exception err)
                            {
                                mMainWindow.ToastNotify(err.ToString(), ToastMessageStyles.Error);
                            }

                            //update locations of gmi and html file
                            gmiFile  = gmiFileNew;
                            htmlFile = htmlFileNew;
                        }
                        else
                        {
                            geminiUri = fullQuery;
                        }

                        var userThemesFolder = ResourceFinder.LocalOrDevFolder(appDir, @"GmiConverters\themes", @"..\..\..\GmiConverters\themes");

                        var userThemeBase = Path.Combine(userThemesFolder, settings.Theme);

                        mMainWindow.ShowUrl(geminiUri, gmiFile, htmlFile, userThemeBase, siteIdentity, e);
                    }
                }

                // codemajor = 3 is redirect - should eventually end in success or raise an error

                else if (geminiResponse.codeMajor == '4')
                {
                    mMainWindow.ToastNotify("Temporary failure (status 4X)\n\n" + e.Uri.ToString(), ToastMessageStyles.Warning);
                }
                else if (geminiResponse.codeMajor == '5')
                {
                    if (geminiResponse.codeMinor == '1')
                    {
                        mMainWindow.ToastNotify("Page not found\n\n" + e.Uri.ToString(), ToastMessageStyles.Warning);
                    }
                    else
                    {
                        mMainWindow.ToastNotify("Permanent failure (status 5X)\n\n" + geminiResponse.meta + "\n\n" + e.Uri.ToString(), ToastMessageStyles.Warning);
                    }
                }
                else if (geminiResponse.codeMajor == '6')
                {
                    mMainWindow.ToastNotify("Certificate requried. Choose one and try again.\n\n" + e.Uri.ToString(), ToastMessageStyles.Warning);
                }

                else
                {
                    mMainWindow.ToastNotify("Unexpected output from server " +
                                            "(status " + geminiResponse.codeMajor + "." + geminiResponse.codeMinor + ") " +
                                            geminiResponse.meta + "\n\n"
                                            + e.Uri.ToString(), ToastMessageStyles.Warning);
                }
            }
            catch (Exception err)
            {
                //generic handler for other runtime errors
                mMainWindow.ToastNotify("Error getting gemini content for " + e.Uri.ToString() + "\n\n" + err.Message, ToastMessageStyles.Warning);
            }


            //make the window responsive again
            mMainWindow.ToggleContainerControlsForBrowser(true);

            //no further navigation right now
            e.Cancel = true;
        }
Exemple #36
0
        static void LoadGeminiLink(Uri uri)
        {
            string         result;
            bool           retrieved = false;
            GeminiResponse resp;

            resp = new GeminiResponse();

            try
            {
                resp      = (GeminiResponse)Gemini.Fetch(uri);
                retrieved = true;
            }
            catch (Exception e)
            {
                //the native gui.cs Messagebox does not resize to show enough content
                //so we use our own that is better
                Dialogs.MsgBoxOK("Gemini error", uri.AbsoluteUri + "\n\n" + e.Message);
            }

            if (retrieved)
            {
                if (resp.codeMajor == '2')
                {
                    //examine the first component of the media type up to any semi colon
                    switch (resp.mime.Split(';')[0].Trim())
                    {
                    case "text/gemini":
                    case "text/plain":
                    case "text/html":
                    {
                        string body = Encoding.UTF8.GetString(resp.bytes.ToArray());

                        result = (body);

                        if (!resp.mime.StartsWith("text/gemini"))
                        {
                            //display as preformatted text
                            result = "```\n" + result + "\n```\n";
                        }

                        break;
                    }

                    default:     // report the mime type only for now
                        result = ("Some " + resp.mime + " content was received, but cannot currently be displayed.");
                        break;
                    }

                    //render the content and add to history
                    SetAsCurrent(resp.uri);             //remember the final URI, since it may have been redirected.

                    if (_history.Count > 0)
                    {
                        _history.Peek().top      = _lineView.TopItem;
                        _history.Peek().selected = _lineView.SelectedItem;        //remember the line offset of the current page
                    }
                    _history.Push(new CachedPage(resp.uri, result, 0, 0));

                    RenderGemini(resp.uri.AbsoluteUri, result, _lineView);
                }
                else if (resp.codeMajor == '1')
                {
                    //input requested from server
                    var userResponse = Dialogs.SingleLineInputBox("Input request from: " + uri.Authority, resp.meta, "");

                    if ((userResponse.ButtonPressed == TextDialogResponse.Buttons.Ok) && (userResponse.Text != ""))
                    {
                        var ub = new UriBuilder(uri);
                        ub.Query = userResponse.Text;

                        LoadGeminiLink(ub.Uri);
                    }
                }
                else if ((resp.codeMajor == '5') && (resp.codeMinor == '1'))
                {
                    //not found
                    Dialogs.MsgBoxOK("Not found", "The resource was not found on the server: \n\n" + resp.uri.AbsoluteUri);
                }
                else
                {
                    Dialogs.MsgBoxOK("Gemini server response", uri.AbsoluteUri + "\n\n" + "Status: " + resp.codeMajor + resp.codeMinor + ": " + resp.meta);
                }
            }
        }
Exemple #37
0
 static MemoizedRecords()
 {
     Gemini.Extend <MemoizedRecords, Memoize>();
 }
        void describe_db_rows_to_json()
        {
            before = () =>
            {
                Seed seed = new Seed();

                seed.PurgeDb();

                seed.CreateTable("Rabbits", seed.Id(), new { Name = "nvarchar(255)" }).ExecuteNonQuery();

                seed.CreateTable("Tasks", seed.Id(), new { Description = "nvarchar(255)" }, new { RabbitId = "int" }).ExecuteNonQuery();

                var rabbitId = new { Name = "YT" }.InsertInto("Rabbits");

                var taskId = new { Description = "bolt onto vans", rabbitId }.InsertInto("Tasks");

                new { Description = "save the world", rabbitId }.InsertInto("Tasks");
            };

            it["disregards self referencing objects"] = () =>
            {
                var results = tasks.All().Include("Rabbits").ToList();

                (results as IEnumerable<dynamic>).ForEach(s =>
                {
                    s.Rabbit = s.Rabbit();
                });

                dynamic newGemini = new Gemini(new { Tasks = results });

                string jsonString = DynamicToJson.Convert(newGemini);

                jsonString.should_be(@"{ ""Tasks"": [ { ""Id"": 1, ""Description"": ""bolt onto vans"", ""RabbitId"": 1, ""Rabbit"": { ""Id"": 1, ""Name"": ""YT"", ""Task"": [ { ""Id"": 2, ""Description"": ""save the world"", ""RabbitId"": 1 } ] } } ] }");
            };
        }
Exemple #39
0
        public async Task <ITickers> GetTicker([FromBody] CompositeStockExchangeObject compositeStockExchangeObject)
        {
            decimal exchangeRate = compositeStockExchangeObject.ExchangeRate;

            Common.StockExchange.Types.StockExchange selectedStockExchange = compositeStockExchangeObject.StockExchange;
            string selectedPairs = compositeStockExchangeObject.SelectedPairs;

            IStockExchanges stockExchanges;

            switch (selectedStockExchange)
            {
            case Common.StockExchange.Types.StockExchange.Binance:
                stockExchanges = new Binance();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Bitfinex:
                stockExchanges = new Bitfinex();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Bitmex:
                stockExchanges = new Bitmex();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Bitstamp:
                stockExchanges = new Bitstamp();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Bittrex:
                stockExchanges = new Bittrex();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Cex:
                stockExchanges = new Cex();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Exmo:
                stockExchanges = new Exmo();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Gdax:
                stockExchanges = new Gdax();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Gemini:
                stockExchanges = new Gemini();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Kraken:
                stockExchanges = new Kraken();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.Poloniex:
                stockExchanges = new Poloniex();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            case Common.StockExchange.Types.StockExchange.QuadrigaCx:
                stockExchanges = new QuadrigaCx();
                return(await stockExchanges.GetTickers(selectedPairs, exchangeRate));

            default:
                throw new NullStockExchangeException("Invalid StockExchange Selection");
            }
        }
Exemple #40
0
 static DynamicRepository()
 {
     WriteDevLog = false;
     LogSql      = LogSqlDelegate;
     Gemini.Extend <DynamicRepository, DynamicQuery>();
 }
Exemple #41
0
        void selecting_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () => gemini = gemini.Select("Term", "Amount");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["collections"] = () =>
            {
                before = () => gemini = new Gemini(new List<string> { "First", "Second" });

                it["initializes a property called items and sets it to the collection"] = () =>
                {
                    (gemini.Items as List<string>).Count().should_be(2);

                    (gemini.Items[0] as string).should_be("First");

                    (gemini.Items[1] as string).should_be("Second");
                };
            };

            context["strings"] = () =>
            {
                before = () => gemini = new Gemini("hello");

                it["initializes a property called value"] = () =>
                    (gemini.Value as object).should_be("hello");
            };

            context["value types"] = () =>
            {
                before = () => gemini = new Gemini(15);

                it["initializes a property called value"] = () =>
                    (gemini.Value as object).should_be(15);
            };

            context["expando object"] = () =>
            {
                before = () =>
                {
                    dynamic expando = new ExpandoObject();
                    expando.FirstName = "First";
                    expando.LastName = "Last";
                    gemini = new Gemini(expando);
                };

                it["doesn't consider an expando object as enumerable"] = () =>
                {
                    (gemini.FirstName as object).should_be("First");

                    (gemini.LastName as object).should_be("Last");
                };
            };

            context["string dictionaries"] = () =>
            {
                before = () =>
                {
                    gemini = new Gemini(new Dictionary<string, object> 
                    { 
                        { "FirstName", "First" },
                        { "LastName", "Last" }
                    });
                };

                it["doesn't consider a IDictionary<string, object> as enumerable"] = () =>
                {
                    (gemini.FirstName as object).should_be("First");

                    (gemini.LastName as object).should_be("Last");
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () =>
                {
                    gemini = gemini.Select("term", "aMount", "dueDate");
                };

                it["case doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("DueDate")).should_be(true);
                };
            };
        }
        void describe_db_rows_to_json()
        {
            before = () =>
            {
                Seed seed = new Seed();

                seed.PurgeDb();

                seed.CreateTable("Rabbits", seed.Id(), new { Name = "nvarchar(255)" }).ExecuteNonQuery();

                seed.CreateTable("Tasks",
                    seed.Id(),
                    new { Description = "nvarchar(255)" },
                    new { RabbitId = "int" },
                    new { DueDate = "datetime" }).ExecuteNonQuery();

                var rabbitId = new { Name = "Yours Truly" }.InsertInto("Rabbits");

                new { rabbitId, Description = "bolt onto vans", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                rabbitId = new { Name = "Hiro Protaganist" }.InsertInto("Rabbits");

                new { rabbitId, Description = "save the world", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                new { rabbitId, Description = "deliver pizza", DueDate = new DateTime(2013, 1, 14) }.InsertInto("Tasks");

                rabbitId = new { Name = "Lots" }.InsertInto("Rabbits");

                for (int i = 0; i < 10; i++)
                {
                    new
                    {
                        rabbitId,
                        Description = "Task: " + i.ToString(),
                        DueDate = new DateTime(2013, 1, 14)
                    }.InsertInto("Tasks");
                }
            };

            it["disregards self referencing objects"] = () =>
            {
                var results = tasks.All().Include("Rabbits").ToList();

                (results as IEnumerable<dynamic>).ForEach(s =>
                {
                    s.Rabbit = s.Rabbit();
                });

                objectToConvert = new Gemini(new { Tasks = results });
                string expected = @"{ ""tasks"": [ { ""id"": 1, ""description"": ""bolt onto vans"", ""rabbitId"": 1, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 1, ""name"": ""Yours Truly"" } }, { ""id"": 2, ""description"": ""save the world"", ""rabbitId"": 2, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 2, ""name"": ""Hiro Protaganist"" } }, { ""id"": 3, ""description"": ""deliver pizza"", ""rabbitId"": 2, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 2, ""name"": ""Hiro Protaganist"" } }, { ""id"": 4, ""description"": ""Task: 0"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 5, ""description"": ""Task: 1"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 6, ""description"": ""Task: 2"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 7, ""description"": ""Task: 3"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 8, ""description"": ""Task: 4"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 9, ""description"": ""Task: 5"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 10, ""description"": ""Task: 6"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 11, ""description"": ""Task: 7"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 12, ""description"": ""Task: 8"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } }, { ""id"": 13, ""description"": ""Task: 9"", ""rabbitId"": 3, ""dueDate"": ""1/14/2013 12:00:00 AM"", ""rabbit"": { ""id"": 3, ""name"": ""Lots"" } } ] }";
                jsonString = DynamicToJson.Convert(objectToConvert);
                jsonString.should_be(expected);
            };
        }
Exemple #43
0
    private void Awake()
    {
        CreateSignNumber();

        mon = new MonsterStat();

        aqua  = new Aquarius();
        arie  = new Aries();
        can   = new Cancer();
        cap   = new Capricorn();
        gem   = new Gemini();
        leo   = new Leo();
        lib   = new Libra();
        pisc  = new Pisces();
        sagi  = new Sagittarius();
        scrop = new Scorpio();
        serp  = new Serpentarius();
        taur  = new Taurus();
        virg  = new Virgo();

        if (SignNumber == 1)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + aqua.Force + MBForce;
            myStats.Vitality  = mon.Vitality + aqua.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + aqua.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + aqua.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + aqua.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + aqua.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + aqua.Charisma + MBCharima;
        }
        if (SignNumber == 2)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + arie.Force + MBForce;
            myStats.Vitality  = mon.Vitality + arie.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + arie.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + arie.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + arie.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + arie.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + arie.Charisma + MBCharima;
        }
        if (SignNumber == 3)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + can.Force + MBForce;
            myStats.Vitality  = mon.Vitality + can.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + can.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + can.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + can.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + can.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + can.Charisma + MBCharima;
        }
        if (SignNumber == 4)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + cap.Force + MBForce;
            myStats.Vitality  = mon.Vitality + cap.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + cap.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + cap.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + cap.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + cap.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + cap.Charisma + MBCharima;
        }
        if (SignNumber == 5)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + gem.Force + MBForce;
            myStats.Vitality  = mon.Vitality + gem.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + gem.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + gem.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + gem.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + gem.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + gem.Charisma + MBCharima;
        }
        if (SignNumber == 6)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + leo.Force + MBForce;
            myStats.Vitality  = mon.Vitality + leo.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + leo.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + leo.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + leo.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + leo.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + leo.Charisma + MBCharima;
        }
        if (SignNumber == 7)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + lib.Force + MBForce;
            myStats.Vitality  = mon.Vitality + lib.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + lib.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + lib.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + lib.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + lib.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + lib.Charisma + MBCharima;
        }
        if (SignNumber == 8)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + pisc.Force + MBForce;
            myStats.Vitality  = mon.Vitality + pisc.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + pisc.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + pisc.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + pisc.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + pisc.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + pisc.Charisma + MBCharima;
        }
        if (SignNumber == 9)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + sagi.Force + MBForce;
            myStats.Vitality  = mon.Vitality + sagi.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + sagi.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + sagi.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + sagi.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + sagi.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + sagi.Charisma + MBCharima;
        }
        if (SignNumber == 10)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + scrop.Force + MBForce;
            myStats.Vitality  = mon.Vitality + scrop.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + scrop.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + scrop.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + scrop.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + scrop.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + scrop.Charisma + MBCharima;
        }
        if (SignNumber == 11)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + serp.Force + MBForce;
            myStats.Vitality  = mon.Vitality + serp.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + serp.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + serp.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + serp.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + serp.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + serp.Charisma + MBCharima;
        }
        if (SignNumber == 12)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + taur.Force + MBForce;
            myStats.Vitality  = mon.Vitality + taur.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + taur.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + taur.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + taur.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + taur.Rational + MBRational;
            myStats.Charisma  = mon.Charisma + taur.Charisma + MBCharima;
        }
        if (SignNumber == 13)
        {
            myStats.Name      = "Fire Cactus";
            myStats.Force     = mon.Force + virg.Force + MBForce;
            myStats.Vitality  = mon.Vitality + virg.Vitality + MBVitality;
            myStats.Agility   = mon.Agility + virg.Agility + MBAgility;
            myStats.Fortiude  = mon.Fortiude + virg.Fortitude + MBFortitude;
            myStats.Intellect = mon.Intellect + virg.Intellect + MBIntellect;
            myStats.Rationale = mon.Rationale + virg.Rationale + MBRational;
            myStats.Charisma  = mon.Charisma + virg.Charisma + MBCharima;
        }

        myStats.HealthPoints  = (myStats.Vitality + myStats.Fortiude) / 2;
        myStats.AbilityPoints = (myStats.Force + myStats.Intellect) / 2;
        myStats.Defence       = myStats.Vitality;
        myStats.AttackDamage  = myStats.Force;
        myStats.AttackSpeed   = myStats.Agility;
        myStats.MagicDefence  = myStats.Rationale;
        myStats.
        AttackBar = 0 / 100;

        //HPthing
        myStats.MaximumHealthPoints = myStats.HealthPoints;
        myStats.HealthPoints        = myStats.MaximumHealthPoints;
        //clamps it
        myStats.HealthPoints = Mathf.Clamp(myStats.HealthPoints, 0, myStats.MaximumHealthPoints);


        // AP bar increasre by timesing agility by time.deltatime
        // divide delta time * agility by 32
    }
Exemple #44
0
        void selecting_properties()
        {
            context["core behavior"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () => gemini = gemini.Select("Term", "Amount");

                it["only responds to properties that were selected"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("Interest")).should_be(false);
                };
            };

            context["collections"] = () =>
            {
                before = () => gemini = new Gemini(new List <string> {
                    "First", "Second"
                });

                it["initializes a property called items and sets it to the collection"] = () =>
                {
                    (gemini.Items as List <string>).Count().should_be(2);

                    (gemini.Items[0] as string).should_be("First");

                    (gemini.Items[1] as string).should_be("Second");
                };
            };

            context["strings"] = () =>
            {
                before = () => gemini = new Gemini("hello");

                it["initializes a property called value"] = () =>
                                                            (gemini.Value as object).should_be("hello");
            };

            context["value types"] = () =>
            {
                before = () => gemini = new Gemini(15);

                it["initializes a property called value"] = () =>
                                                            (gemini.Value as object).should_be(15);
            };

            context["expando object"] = () =>
            {
                before = () =>
                {
                    dynamic expando = new ExpandoObject();
                    expando.FirstName = "First";
                    expando.LastName  = "Last";
                    gemini            = new Gemini(expando);
                };

                it["doesn't consider an expando object as enumerable"] = () =>
                {
                    (gemini.FirstName as object).should_be("First");

                    (gemini.LastName as object).should_be("Last");
                };
            };

            context["string dictionaries"] = () =>
            {
                before = () =>
                {
                    gemini = new Gemini(new Dictionary <string, object>
                    {
                        { "FirstName", "First" },
                        { "LastName", "Last" }
                    });
                };

                it["doesn't consider a IDictionary<string, object> as enumerable"] = () =>
                {
                    (gemini.FirstName as object).should_be("First");

                    (gemini.LastName as object).should_be("Last");
                };
            };

            context["casing"] = () =>
            {
                before = () => gemini = new Gemini(new { Term = 10, Amount = 100000, Interest = .30, DueDate = DateTime.Today });

                act = () =>
                {
                    gemini = gemini.Select("term", "aMount", "dueDate");
                };

                it["case doesn't matter"] = () =>
                {
                    ((bool)gemini.RespondsTo("Term")).should_be(true);

                    ((bool)gemini.RespondsTo("Amount")).should_be(true);

                    ((bool)gemini.RespondsTo("DueDate")).should_be(true);
                };
            };
        }
Exemple #45
0
        void converting_nested_object()
        {
            before = () =>
            {
                objectToConvert = new Gemini(
                new
                {
                    Id = 15,
                    Name = "Mirror's Edge",
                    Owner = new Gemini(new
                    {
                        Id = 22,
                        Handle = "@amirrajan"
                    })
                });
            };

            act = () => jsonString = DynamicToJson.Convert(objectToConvert);

            it["converts whole object graph"] = () =>
            {
                string expected = @"{ ""id"": 15, ""name"": ""Mirror's Edge"", ""owner"": { ""id"": 22, ""handle"": ""@amirrajan"" } }";

                jsonString.should_be(expected);
            };
        }