Esempio n. 1
0
        private ApiResponse WhenTryPost(string templateType, SetupData setup)
        {
            var command = GivenValidEmailTemplateSaveCommand();
            var json    = JsonSerialiser.Serialise(command);

            return(WhenTryPost(json, templateType, setup));
        }
Esempio n. 2
0
        /// <summary>
        /// Saves an object to a root using the specified settings, overwriting if it exists
        /// </summary>
        /// <typeparam name="T">The type of object to save</typeparam>
        /// <param name="root">The root this object will be saved under</param>
        /// <param name="value">The object to save</param>
        /// <param name="settings">Settings</param>
        public static void Save <T>(string root, T value, QuickSaveSettings settings)
        {
            string jsonToSave;

            try
            {
                jsonToSave = JsonSerialiser.Serialise(TypeHelper.ReplaceIfUnityType(value));
            }
            catch (Exception e)
            {
                throw new QuickSaveException("Json serialisation failed", e);
            }

            string encryptedJson;

            try
            {
                encryptedJson = Cryptography.Encrypt(jsonToSave, settings.SecurityMode, settings.Password);
            }
            catch (Exception e)
            {
                throw new QuickSaveException("Encryption failed", e);
            }

            if (!FileAccess.SaveString(root, false, encryptedJson))
            {
                throw new QuickSaveException("Failed to write to file");
            }
        }
Esempio n. 3
0
        private ApiResponse WhenTryPostAnonymously(ApiEmailTemplateSaveCommand command, string templateType, SetupData setup)
        {
            var json         = JsonSerialiser.Serialise(command);
            var relativePath = string.Format("{0}/{1}", RelativePath, templateType);

            return(BusinessAnonymousPost <LocationData>(json, relativePath, setup));
        }
Esempio n. 4
0
        private static string CreateNewServiceSaveCommand(ExpectedService expectedService)
        {
            var command = new ApiServiceSaveCommand
            {
                name         = expectedService.Name,
                description  = expectedService.Description,
                repetition   = expectedService.Repetition,
                presentation = expectedService.Presentation
            };

            if (expectedService.Timing != null)
            {
                command.timing = expectedService.Timing;
            }
            if (expectedService.Pricing != null)
            {
                command.pricing = expectedService.Pricing;
            }
            if (expectedService.Booking != null)
            {
                command.booking = expectedService.Booking;
            }

            return(JsonSerialiser.Serialise(command));
        }
        /// <summary>
        /// POST请求与获取结果
        /// </summary>
        public static string HttpPostWebhook(string Url, string accessToken)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  // 加入这一句,否则会报错:未能创建SSL/TLS安全通道

            JsonSerialiser jsonSerialiser = new JsonSerialiser();
            WebhookData    postData       = new WebhookData();
            string         postJson       = jsonSerialiser.Serialise(postData);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

            request.Method      = "POST";
            request.ContentType = "application/json;";
            request.Headers.Add("Authorization", "Token " + accessToken);
            request.UserAgent = "2426837192";

            using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(postJson);
                writer.Flush();
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string          encoding = response.ContentEncoding;

            if (encoding == null || encoding.Length < 1)
            {
                encoding = "UTF-8"; //默认编码
            }
            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding)))
            {
                string retString = reader.ReadToEnd();
                return(retString);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Commits the changes to file
        /// </summary>
        public void Commit()
        {
            string jsonToSave;

            try
            {
                jsonToSave = JsonSerialiser.Serialise(_items);
            }
            catch (Exception e)
            {
                throw new QuickSaveException("Json serialisation failed", e);
            }

            string encryptedJson;

            try
            {
                encryptedJson = Cryptography.Encrypt(jsonToSave, _settings.SecurityMode, _settings.Password);
            }
            catch (Exception e)
            {
                throw new QuickSaveException("Encryption failed", e);
            }

            if (!FileAccess.SaveString(_root, false, encryptedJson))
            {
                throw new QuickSaveException("Failed to write to file");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Attempts to load an object from a root under the specified key using the specified settings
        /// </summary>
        /// <typeparam name="T">The type of object to load</typeparam>
        /// <param name="root">The root this object was saved under</param>
        /// <param name="key">The key this object was saved under</param>
        /// <param name="settings">Settings</param>
        /// <param name="result">The object that was loaded</param>
        /// <returns>Was the load successful</returns>
        public static bool TryLoad <T>(string root, string key, QuickSaveSettings settings, out T result)
        {
            result = default(T);

            try
            {
                string fileJson = FileAccess.LoadString(root, false);

                if (string.IsNullOrEmpty(fileJson))
                {
                    return(false);
                }

                string decryptedJson = Cryptography.Decrypt(fileJson, settings.SecurityMode, settings.Password);

                Dictionary <string, object> items = JsonSerialiser.Deserialise <Dictionary <string, object> >(decryptedJson) ?? new Dictionary <string, object>();

                if (!items.ContainsKey(key))
                {
                    return(false);
                }

                string propertyJson = JsonSerialiser.Serialise(items[key]);

                result = JsonSerialiser.Deserialise <T>(propertyJson);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 8
0
            private string GivenWantToUpdateExistingService(SetupData setup)
            {
                var command = new ApiServiceSaveCommand
                {
                    id          = setup.MiniRed.Id,
                    name        = "Mini Yellow",
                    description = "Mini Yellow Service",
                    timing      = new ApiServiceTiming {
                        duration = 60
                    },
                    booking = new ApiServiceBooking {
                        studentCapacity = 12, isOnlineBookable = true
                    },
                    presentation = new ApiPresentation {
                        colour = "Yellow"
                    },
                    repetition = new ApiServiceRepetition {
                        sessionCount = 9, repeatFrequency = "d"
                    },
                    pricing = new ApiPricing {
                        sessionPrice = 10, coursePrice = 80
                    }
                };

                return(JsonSerialiser.Serialise(command));
            }
Esempio n. 9
0
        private void WhenTrySetAttendance(ApiBookingSetAttendanceCommand command, SetupData setup)
        {
            var json         = JsonSerialiser.Serialise(command);
            var relativePath = string.Format("{0}/{1}", RelativePath, setup.FredOnAaronOrakeiMiniRed14To15.Id);

            WhenTrySetAttendance(json, relativePath, setup);
        }
Esempio n. 10
0
        private object WhenTrySetPaymentStatusForCourseBooking(ApiBookingSetPaymentStatusCommand command, SetupData setup)
        {
            RegisterFredOnTwoCourseSessionsInAaronOrakeiHolidayCamp9To15For3Days(setup);

            var json         = JsonSerialiser.Serialise(command);
            var relativePath = string.Format("{0}/{1}", RelativePath, setup.FredOnAaronOrakeiHolidayCamp9To15For3Days.Id);

            return(WhenTrySetPaymentStatus(json, relativePath, setup));
        }
Esempio n. 11
0
        private object WhenTrySetPaymentStatusForSessionBooking(ApiBookingSetPaymentStatusCommand command, SetupData setup)
        {
            RegisterFredOnStandaloneAaronOrakeiMiniRed14To15(setup);

            var json         = JsonSerialiser.Serialise(command);
            var relativePath = string.Format("{0}/{1}", RelativePath, setup.FredOnAaronOrakeiMiniRed14To15.Id);

            return(WhenTrySetPaymentStatus(json, relativePath, setup));
        }
Esempio n. 12
0
            private string GivenValidLocationSaveCommand()
            {
                var command = new ApiLocationSaveCommand
                {
                    name = "Mt Eden Soccer Club"
                };

                return(JsonSerialiser.Serialise(command));
            }
        private ApiResponse WhenTryUpdateAuthorisedUntil(ApiBusinessSetAuthorisedUntilCommand command, SetupData setup)
        {
            var url      = string.Format("Businesses/{0}", setup.Business.Id);
            var json     = JsonSerialiser.Serialise(command);
            var response = AdminPost(json, url);

            setup.Business.AuthorisedUntil = command.authorisedUntil;
            return(response);
        }
Esempio n. 14
0
            private string GivenNewUniqueLocation()
            {
                var command = new ApiLocationSaveCommand
                {
                    name = "Mt Eden Squash Club"
                };

                return(JsonSerialiser.Serialise(command));
            }
Esempio n. 15
0
        private static string CreateNewCoachSaveCommand(ExpectedLocation expectedLocation)
        {
            var command = new ApiLocationSaveCommand
            {
                name = expectedLocation.Name
            };

            return(JsonSerialiser.Serialise(command));
        }
Esempio n. 16
0
            private string GivenNewLocationWithAnAlreadyExistingLocationName(string duplicateLocationName)
            {
                var command = new ApiLocationSaveCommand
                {
                    name = duplicateLocationName
                };

                return(JsonSerialiser.Serialise(command));
            }
Esempio n. 17
0
            private string GivenExistingLocationAndKeepLocationNameSame(SetupData setup)
            {
                var command = new ApiLocationSaveCommand
                {
                    id   = setup.Orakei.Id,
                    name = setup.Orakei.Name
                };

                return(JsonSerialiser.Serialise(command));
            }
Esempio n. 18
0
            private string GivenExistingLocationAndChangeToAnAlreadyExistingLocationName(SetupData setup)
            {
                var command = new ApiLocationSaveCommand
                {
                    id   = setup.Remuera.Id,
                    name = setup.Orakei.Name
                };

                return(JsonSerialiser.Serialise(command));
            }
        private void SetBusinessAsExpired(SetupData setup)
        {
            var command = new ApiBusinessSetAuthorisedUntilCommand {
                authorisedUntil = DateTime.UtcNow.AddMonths(-1)
            };
            var url  = string.Format("Businesses/{0}", setup.Business.Id);
            var json = JsonSerialiser.Serialise(command);

            AdminPost(json, url);
        }
        private string GivenMissingProperties()
        {
            var registration = new ApiBusinessRegistrationCommand
            {
                business = new ApiBusiness(),
                admin    = new ApiBusinessAdmin()
            };

            return(JsonSerialiser.Serialise(registration));
        }
        private void UpdateSessionPriceOfLastSessionOfAaronOrakeiHolidayCamp9To15For3Days(SetupData setup)
        {
            var command = new ApiSessionSaveCommand(setup.AaronOrakeiHolidayCamp9To15For3Days.Sessions[2])
            {
                id      = setup.AaronOrakeiHolidayCamp9To15For3Days.Sessions[2].Id,
                pricing = { sessionPrice = 75 }
            };

            PostSession(JsonSerialiser.Serialise(command), setup);
        }
Esempio n. 22
0
            private string GivenExistingLocationAndChangeToUniqueLocationName(SetupData setup, string newLocationName)
            {
                var command = new ApiLocationSaveCommand
                {
                    id   = setup.Orakei.Id,
                    name = newLocationName
                };

                return(JsonSerialiser.Serialise(command));
            }
        private static string CreateNewCustomerSaveCommand(ExpectedCustomer expectedCustomer)
        {
            var command = new ApiCustomerSaveCommand
            {
                firstName = expectedCustomer.FirstName,
                lastName  = expectedCustomer.LastName,
                email     = expectedCustomer.Email,
                phone     = expectedCustomer.Phone
            };

            return(JsonSerialiser.Serialise(command));
        }
Esempio n. 24
0
        private static string CreateNewCoachSaveCommand(ExpectedCoach expectedCoach)
        {
            var command = new ApiCoachSaveCommand
            {
                firstName    = expectedCoach.FirstName,
                lastName     = expectedCoach.LastName,
                email        = expectedCoach.Email,
                phone        = expectedCoach.Phone,
                workingHours = expectedCoach.WorkingHours
            };

            return(JsonSerialiser.Serialise(command));
        }
        private string GivenNonExistentCustomerId()
        {
            var command = new ApiCustomerSaveCommand
            {
                id        = Guid.Empty,
                firstName = Random.RandomString,
                lastName  = Random.RandomString,
                email     = Random.RandomEmail,
                phone     = Random.RandomString,
            };

            return(JsonSerialiser.Serialise(command));
        }
            private string GivenNewCoachWithAnAlreadyExistingCoachName(SetupData setup)
            {
                var command = new ApiCoachSaveCommand
                {
                    firstName    = setup.Aaron.FirstName,
                    lastName     = setup.Aaron.LastName,
                    email        = Random.RandomEmail,
                    phone        = Random.RandomString,
                    workingHours = SetupStandardWorkingHours()
                };

                return(JsonSerialiser.Serialise(command));
            }
            private string GivenNonExistentCoachId()
            {
                var command = new ApiCoachSaveCommand
                {
                    id           = Guid.Empty,
                    firstName    = Random.RandomString,
                    lastName     = Random.RandomString,
                    email        = Random.RandomEmail,
                    phone        = Random.RandomString,
                    workingHours = SetupStandardWorkingHours()
                };

                return(JsonSerialiser.Serialise(command));
            }
            private string GivenWantToUpdateExistingCoach(SetupData setup)
            {
                var command = new ApiCoachSaveCommand
                {
                    id           = setup.Aaron.Id,
                    firstName    = "Adam",
                    lastName     = "Ant",
                    email        = "*****@*****.**",
                    phone        = "021 0123456",
                    workingHours = SetupWeekendWorkingHours()
                };

                return(JsonSerialiser.Serialise(command));
            }
        private static string CreateNewBusinessSaveCommand(ExpectedBusiness expectedBusiness)
        {
            var command = new ApiBusinessRegistrationCommand
            {
                business = new ApiBusiness
                {
                    name     = expectedBusiness.Name,
                    sport    = expectedBusiness.Sport,
                    currency = expectedBusiness.Payment.currency
                },
                admin = expectedBusiness.Admin
            };

            return(JsonSerialiser.Serialise(command));
        }
            private string GivenValidNewCoach()
            {
                var command = new ApiCoachSaveCommand
                {
                    firstName    = "Carl",
                    lastName     = "Carson",
                    email        = "*****@*****.**",
                    phone        = "021 69 69 69",
                    workingHours = SetupStandardWorkingHours()
                };

                command.workingHours.sunday = new ApiDailyWorkingHours(false, "10:30", "15:45");

                return(JsonSerialiser.Serialise(command));
            }