public void WhenABillIsRequested_ThenABillShouldBeReturned() { // Arrange var id = 1; var bill = new Bill { CallCharges = new CallCharges { Calls = new List<Call> { new Call { Called = string.Empty, Cost = 0.00, Duration = string.Empty } } }, Package = new Package { Subscriptions = new List<Subscription> { new Subscription { Type = string.Empty, Cost = 0.00, Name = string.Empty } } }, SkyStore = new SkyStore { BuyAndKeeps = new List<BuyAndKeep> { new BuyAndKeep { Cost = 0.00, Title = string.Empty } } }, Statement = new Statement { Due = DateTime.Now, Generated = DateTime.Now, Period = new Period { From = DateTime.Now, To = DateTime.Now } }, Total = 0.00 }; var validator = Substitute.For<IValidator<BillValidator>>(); validator.Validate(bill).Returns(new ValidationResult { }); var _billingRepository = Substitute.For<IBillingRepository>(); _billingRepository.Get(id) .Returns(bill); var _billingService = new BillingService(_billingRepository, validator); // Act var actual = _billingService.Get(id); //Assert Assert.NotNull(actual); }
void WhenAFileDoesNotExist_ThenAnEmptyObjectShouldBeReturned() { // Arrange var id = 0; var expected = new Bill(); var repository = new BillingRepository(); // Act var actual = repository.Get(id); // Assert Assert.Null(actual); }
void WhenABillIsRequested_ThenABillShouldBeReturned() { // Arrange var id = 1; var expected = new Bill(); var repository = new BillingRepository(); // Act var actual = repository.Get(id); // Assert Assert.NotNull(actual.Statement.Due); }
public Bill Get(int id) { try { using (StreamReader r = new StreamReader(string.Format("{0}/{1}/{2}", AppDomain.CurrentDomain.BaseDirectory, _dataStore, string.Format("{0}{1}", id, ".json")))) { string json = r.ReadToEnd(); _result = JsonConvert.DeserializeObject<Bill>(json); } } catch(Exception ex) { _result = null; } return _result; }
public void WhenBillingIsRequested_ThenAValidResponseShouldbeReturned() { // Arrange var id = 1; var bootstrapper = new Bootstrapper(); var browser = new Browser(bootstrapper); var expected = new Bill(); var service = Substitute.For<IBillingService>(); service.Get(id).Returns(expected); // Act var result = browser.Get("/billing", with => { with.HttpRequest(); }); // Assert Assert.Equal(HttpStatusCode.OK, result.StatusCode); }