public void TestCalculateChangeList() {

            WhereIsMyChangeManager whereIsMyChangeManager = new WhereIsMyChangeManager();
            PrivateObject privateObject = new PrivateObject(whereIsMyChangeManager);
            object response = privateObject.Invoke("CalculateChangeList", 987654321555666);
             
            List<KeyValuePair<int, long>> calculateChangeList = (List<KeyValuePair<int, long>>)response;

            Assert.IsNotNull(calculateChangeList);
        }
예제 #2
0
        private void CalculateChange() {
            this.UxTxtChangeAmount.Text = string.Empty;
            ChangeRequest changeRequest = new ChangeRequest();
            long productAmount;
            long paidAmount;
            ErrorCollection = new List<string>();

            if (long.TryParse(this.UxTxtProductAmount.Text, out productAmount) == false) {
                this.ErrorCollection.Add("Valor do produto precisa ser inteiro.");
            }
            if (long.TryParse(this.UxTxtPaidAmount.Text, out paidAmount) == false) {
                this.ErrorCollection.Add("Valor pago precisa ser inteiro.");
            }
            if (paidAmount < productAmount) {
                this.ErrorCollection.Add("O valor pago precisa ser igual ou maior do que o valor do produto.");
            }
            if (this.ErrorCollection.Any()) {
                foreach (string error in this.ErrorCollection) {
                    this.UxTxtChangeAmount.Text += error + Environment.NewLine;
                }
                return;
            }

            IWhereIsMyChangeManager whereIsMyChange = new WhereIsMyChangeManager();

            changeRequest.PaidAmount = paidAmount;
            changeRequest.ProductAmount = productAmount;

            ChangeResponse changeResponse = whereIsMyChange.CalculateChange(changeRequest);

            if (changeResponse.OperationReportList != null && changeResponse.OperationReportList.Any()) {
                foreach (OperationReport operationReport in changeResponse.OperationReportList) {

                    this.UxTxtChangeAmount.Text += string.Format("{0} - {1}{2}", operationReport.Field, operationReport.Message, Environment.NewLine);
                }
            } else {
                foreach (var item in changeResponse.ChangeList) {
                    this.UxTxtChangeAmount.Text += string.Format("{0}: {1} {2}", item.Key, item.Value, Environment.NewLine);
                }
                this.UxTxtChangeAmount.Text += string.Format("Troco: {0}{1}", changeResponse.ChangeAmount, Environment.NewLine);
            }
        }