예제 #1
0
        public void Test_PrescriptionJSONPresenter_Serializability()
        {
            var placeDate = "Bern, 20.10.2016 (17:01:31)";
            var hash      = Utilities.GenerateUUID();
            var presenter = new PrescriptionJSONPresenter(hash, placeDate);

            var expected = String.Format(WHITESPACES.Replace(@"{{
                ""prescription_hash"":{0},
                ""place_date"":{1},
                ""operator"":{2},
                ""patient"":{3},
                ""medications"":{4}
            }}", ""),
                                         GetStringValue(hash),
                                         GetStringValue(placeDate),
                                         GetStringValue(null),
                                         GetStringValue(null),
                                         GetStringValue <Medication>(new List <Medication>())
                                         );

            string resultJSON = Serializer.Serialize(presenter);

            Assert.AreEqual(expected, resultJSON);
            Assert.IsTrue(Serializer.Deserialize <Account>(resultJSON) is Account);
        }
예제 #2
0
        public void Test_PrescriptionJSONPresenter_Properties()
        {
            Contact contact = new Contact();
            Dictionary <string, string> contactProperties = new Dictionary <string, string>();

            contactProperties.Add("Uid", contact.GenerateUid());
            contactProperties.Add("GivenName", "John");
            contactProperties.Add("FamilyName", "Smith");
            contactProperties.Add("Birthdate", "3.12.2001");
            contactProperties.Add("Gender", "1");
            contactProperties.Add("WeightKg", "70.3");
            contactProperties.Add("HeightCm", "186");
            contactProperties.Add("Zip", "123");
            contactProperties.Add("Country", "Schweiz");
            contactProperties.Add("Address", "Internetstrasse 42");
            contactProperties.Add("Phone", "+00 123 456 789 0");
            contactProperties.Add("Email", "*****@*****.**");

            foreach (KeyValuePair <string, string> entry in contactProperties)
            {
                contact[entry.Key] = (string)entry.Value;
            }

            Account account = new Account();
            Dictionary <string, string> accountProperties = new Dictionary <string, string>();

            accountProperties.Add("Title", "Dr.");
            accountProperties.Add("GivenName", "John");
            accountProperties.Add("FamilyName", "Smith");
            accountProperties.Add("Zip", "123");
            accountProperties.Add("Address", "Internetstrasse 42");
            accountProperties.Add("Phone", "+00 123 456 789 0");
            accountProperties.Add("Email", "*****@*****.**");

            foreach (KeyValuePair <string, string> entry in accountProperties)
            {
                account[entry.Key] = (string)entry.Value;
            }

            var placeDate = "Bern, 20.10.2016 (17:01:31)";
            var hash      = Utilities.GenerateUUID();
            var presenter = new PrescriptionJSONPresenter(hash, placeDate);

            // set properties
            presenter.Contact         = contact;
            presenter.Account         = account;
            presenter.MedicationsList = new List <Medication>();

            string resultJSON = Serializer.Serialize(presenter);

            Assert.IsTrue(resultJSON.Contains(placeDate));
            Assert.IsTrue(resultJSON.Contains(hash));

            foreach (KeyValuePair <string, string> entry in contactProperties)
            {
                Assert.IsTrue(resultJSON.Contains(entry.Value));
            }

            foreach (KeyValuePair <string, string> entry in accountProperties)
            {
                Assert.IsTrue(resultJSON.Contains(entry.Value));
            }

            Assert.IsTrue(resultJSON.Contains(account.Signature));
        }