Ejemplo n.º 1
0
        public void CalculateEntities_GetChangeWithCoinsOnly_Test()
        {
            CadeMeuTrocoManager manager = new CadeMeuTrocoManager();

            PrivateObject privateObject = new PrivateObject(manager);
            object        objResult     = privateObject.Invoke("CalculateEntities", Convert.ToInt64(170));

            IEnumerable <ChangeData> result = (IEnumerable <ChangeData>)objResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 1);

            ChangeData changeData = result.ElementAt(0);

            Assert.IsTrue("Coin".Equals(changeData.Name, StringComparison.InvariantCultureIgnoreCase) == true);

            Assert.IsTrue(changeData.ChangeDictionary.Count == 3);

            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(100) == true);
            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(50) == true);
            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(10) == true);

            Assert.AreEqual(1, changeData.ChangeDictionary[100]);
            Assert.AreEqual(1, changeData.ChangeDictionary[50]);
            Assert.AreEqual(2, changeData.ChangeDictionary[10]);
        }
Ejemplo n.º 2
0
        private void Calculate()
        {
            this.UxTxtProcessorResult.Clear();
            this.UxTxtResult.Clear();


            long productAmount = Convert.ToInt64(this.UxTxtProductValue.Text);
            long paidAmount    = Convert.ToInt64(this.UxTxtPaidValue.Text);

            CadeMeuTrocoManager manager = new CadeMeuTrocoManager();

            manager.OnProcessorExecuted += manager_OnProcessorExecuted;

            CalculateRequest request = new CalculateRequest();

            request.PaidAmountInCents    = paidAmount;
            request.ProductAmountInCents = productAmount;


            ILog log = new FileLog();

            log.Save("Calculate", "IT'S DONE M**********R!", CategoryType.Exception);

            CalculateResponse response = manager.Calculate(request);

            if (response.Success == false)
            {
                StringBuilder stringBuilder = new StringBuilder();

                foreach (Report report in response.ReportCollection)
                {
                    stringBuilder.AppendLine(string.Format("{0}: {1}", report.Field, report.Message));
                }

                this.UxTxtResult.Text = stringBuilder.ToString();
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendLine(string.Format("Valor total: {0}", response.ChangeAmount.Value));

                //Percorre a lista de moedas e exibe a resposta
                foreach (ChangeData data in response.ChangeCollection)
                {
                    foreach (KeyValuePair <int, long> change in data.ChangeDictionary.Where(p => p.Value > 0))
                    {
                        stringBuilder.AppendLine(string.Format("{0}: {1} | Quantidade: {2}", data.Name, change.Key, change.Value));
                    }
                }

                this.UxTxtResult.Text = stringBuilder.ToString();
            }
        }
Ejemplo n.º 3
0
        public void CalculateEntities_GetEmptyChangeDataCollection_Test()
        {
            CadeMeuTrocoManager manager = new CadeMeuTrocoManager();

            PrivateObject privateObject = new PrivateObject(manager);
            object        objResult     = privateObject.Invoke("CalculateEntities", Convert.ToInt64(0));

            IEnumerable <ChangeData> result = (IEnumerable <ChangeData>)objResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 0);
        }
Ejemplo n.º 4
0
        public void Calculate_GetChangeDataWithCoinsOnly_Test()
        {
            ConfigurationUtilityMock mock = new ConfigurationUtilityMock();

            mock.LogPath = "C:\\Logs\\Test";

            IocFactory.Register(
                Component.For <IConfigurationUtility>().Instance(mock),
                Component.For <ILog>().ImplementedBy <FileLog>().IsDefault()
                );

            CadeMeuTrocoManager manager = new CadeMeuTrocoManager();

            CalculateRequest request = new CalculateRequest();

            request.ProductAmountInCents = 100;
            request.PaidAmountInCents    = 140;

            CalculateResponse response = manager.Calculate(request);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success == true);
            Assert.IsTrue(response.ChangeAmount == 40);
            Assert.IsTrue(response.ChangeCollection.Count() == 1);

            ChangeData changeData = response.ChangeCollection.First();

            Assert.IsTrue(changeData.Name == "Coin");
            Assert.IsTrue(changeData.ChangeDictionary.Count() == 3);
            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(25) == true);
            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(10) == true);
            Assert.IsTrue(changeData.ChangeDictionary.ContainsKey(5) == true);
            Assert.AreEqual(1, changeData.ChangeDictionary[25]);
            Assert.AreEqual(1, changeData.ChangeDictionary[10]);
            Assert.AreEqual(1, changeData.ChangeDictionary[5]);
        }