public ActionResult Calculate(int?treeDiameter, int?typeId, int?treesCount) { if (treeDiameter == null || typeId == null || treesCount == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Parameters cannot be null")); } if (treeDiameter < 0 || typeId < 0 || treesCount < 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Parameters cannot be negative numbers")); } var valkaType = _valkaTypes.FirstOrDefault(type => type.Id == typeId); if (valkaType == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Не проходит")); } var price = treeDiameter * valkaType.Coefficient * treesCount; var result = new CalculatingResult { ValkaTypeName = valkaType.Name, TreesCount = treesCount.Value, Price = price.Value, TreeDiameter = treeDiameter.Value }; return(View("CalculatingResult", result)); }
public void ShowAnswer(CalculatingResult res) { switch (res) { case CalculatingResult.NotEnoughData: Console.WriteLine("You don't enter all required data."); break; case CalculatingResult.FirstToSecond: Console.WriteLine("You can put the first envelope to second."); break; case CalculatingResult.SecondToFirst: Console.WriteLine("You can put the second envelope to first."); break; case CalculatingResult.Equal: Console.WriteLine("Envelopes are equal."); break; case CalculatingResult.NoOne: Console.WriteLine("No envelope can be inserted into another."); break; default: break; } }
public void Result_NoTwoEnvelopesAdded_NotEnoughData() { CalculatingResult request = CalculatingResult.NotEnoughData; Mock <IEnvelopeCreator> eCreator = new Mock <IEnvelopeCreator>(); Mock <IComparer <Envelope> > comparor = new Mock <IComparer <Envelope> >(); EnvelopesStorage envelopesStorage = new EnvelopesStorage(eCreator.Object, comparor.Object); CalculatingResult result = envelopesStorage.Result(); Assert.AreEqual(request, result); }
public void Result_NoOneCanBePutToNoOne_NoOne() { CalculatingResult request = CalculatingResult.NoOne; Mock <IEnvelopeCreator> eCreator = new Mock <IEnvelopeCreator>(); Mock <IComparer <Envelope> > comparor = new Mock <IComparer <Envelope> >(); EnvelopesStorage envelopesStorage = new EnvelopesStorage(eCreator.Object, comparor.Object); envelopesStorage.Envelope1 = new Envelope(2, 2); envelopesStorage.Envelope2 = new Envelope(1, 3); comparor.Setup(x => x.Compare(It.IsAny <Envelope>(), It.IsAny <Envelope>())).Returns(-1); CalculatingResult result = envelopesStorage.Result(); Assert.AreEqual(result, request); }
public void Result_EqualEnvelops_Equal() { CalculatingResult request = CalculatingResult.Equal; Mock <IEnvelopeCreator> eCreator = new Mock <IEnvelopeCreator>(); Mock <IComparer <Envelope> > comparor = new Mock <IComparer <Envelope> >(); EnvelopesStorage envelopesStorage = new EnvelopesStorage(eCreator.Object, comparor.Object); envelopesStorage.Envelope1 = new Envelope(1, 1); envelopesStorage.Envelope2 = new Envelope(1, 1); comparor.Setup(x => x.Compare(It.IsAny <Envelope>(), It.IsAny <Envelope>())).Returns(0); CalculatingResult result = envelopesStorage.Result(); Assert.AreEqual(result, request); }
public void Result_SeconBiggerThanFirst_FirstToSecond() { CalculatingResult request = CalculatingResult.FirstToSecond; Mock <IEnvelopeCreator> eCreator = new Mock <IEnvelopeCreator>(); Mock <IComparer <Envelope> > comparor = new Mock <IComparer <Envelope> >(); EnvelopesStorage envelopesStorage = new EnvelopesStorage(eCreator.Object, comparor.Object); envelopesStorage.Envelope1 = new Envelope(1, 1); envelopesStorage.Envelope2 = new Envelope(10, 10); comparor.Setup(x => x.Compare(It.IsAny <Envelope>(), It.IsAny <Envelope>())).Returns(-1); comparor.Setup(x => x.Compare(It.Is <Envelope>(val => val.Equals(envelopesStorage.Envelope2)), It.Is <Envelope>(val => val.Equals(envelopesStorage.Envelope1)))).Returns(1); CalculatingResult result = envelopesStorage.Result(); Assert.AreEqual(result, request); }