public void ItemNotFound_ReturnsFalse() { // Arrange var dataStoreMock = new Mock <IDataStore>(MockBehavior.Strict); dataStoreMock.SetupProperty(p => p.Items, new List <Item>()); var bidService = new BidService(dataStoreMock.Object); var unknownId = _randomInteger.GeneratePositiveValue().ToString(); var userId = _randomString.GenerateValue(8); var serviceModel = new BidCreateServiceModel { Amount = _randomDecimal.GeneratePositiveValue(), ItemId = unknownId, UserId = userId, MadeOn = DateTime.UtcNow }; // Act var result = bidService.CreateBid(serviceModel); // Assert Assert.IsFalse(result, "Incorrect result returned"); }
public void ItemsAvailable_ListReturned() { // Arrange var description1 = _randomString.GenerateValue(50); var description2 = _randomString.GenerateValue(50); var endTime1 = DateTime.Now.AddHours(3); var endTime2 = DateTime.Now.AddHours(4); var id1 = _randomInteger.GeneratePositiveValue(); var id2 = _randomInteger.GeneratePositiveValue(); const string picturePath1 = "ABC"; const string picturePath2 = "XYZ"; var price1 = _randomDecimal.GeneratePositiveValue(); var price2 = _randomDecimal.GeneratePositiveValue(); var startTime1 = DateTime.Now.AddHours(-13); var startTime2 = DateTime.Now.AddHours(-20); var title1 = _randomString.GenerateValue(10); var title2 = _randomString.GenerateValue(10); var userId1 = _randomString.GenerateValue(8); var userId2 = _randomString.GenerateValue(8); var dataStoreMock = new Mock <IDataStore>(MockBehavior.Strict); dataStoreMock.SetupProperty(p => p.Items, new List <Item> { new Item { Description = description1, EndTime = endTime1, Id = id1.ToString(), PicturePath = picturePath1, Price = price1, StartTime = startTime1, Title = title1, UserId = userId1 }, new Item { Description = description2, EndTime = endTime2, Id = id2.ToString(), PicturePath = picturePath2, Price = price2, StartTime = startTime2, Title = title2, UserId = userId2 } }); var itemsService = new ItemsService(dataStoreMock.Object); // Act var result = itemsService.GetAllItems(); // Assert Assert.IsNotNull(result, "result != null"); Assert.AreEqual(2, result.Count(), "Incorrect number of items returned"); Assert.IsTrue(result.Any(i => i.Id == id1.ToString() && i.PicturePath == picturePath1 && i.Price == price1 && i.Title == title1), "Item 1 not returned"); Assert.IsTrue(result.Any(i => i.Id == id2.ToString() && i.PicturePath == picturePath2 && i.Price == price2 && i.Title == title2), "Item 2 not returned"); }
public void ItemAvailable_ItemReturned() { // Arrange var description1 = _randomString.GenerateValue(50); var description2 = _randomString.GenerateValue(50); var endTime1 = DateTime.Now.AddHours(3); var endTime2 = DateTime.Now.AddHours(4); var id1 = _randomInteger.GeneratePositiveValue(); var id2 = _randomInteger.GeneratePositiveValue(); const string picturePath1 = "ABC"; const string picturePath2 = "XYZ"; var price1 = _randomDecimal.GeneratePositiveValue(); var price2 = _randomDecimal.GeneratePositiveValue(); var startTime1 = DateTime.Now.AddHours(-13); var startTime2 = DateTime.Now.AddHours(-20); var title1 = _randomString.GenerateValue(10); var title2 = _randomString.GenerateValue(10); var userId1 = _randomString.GenerateValue(8); var userId2 = _randomString.GenerateValue(8); var dataStoreMock = new Mock <IDataStore>(MockBehavior.Strict); dataStoreMock.SetupProperty(p => p.Items, new List <Item> { new Item { Description = description1, EndTime = endTime1, Id = id1.ToString(), PicturePath = picturePath1, Price = price1, StartTime = startTime1, Title = title1, UserId = userId1 }, new Item { Description = description2, EndTime = endTime2, Id = id2.ToString(), PicturePath = picturePath2, Price = price2, StartTime = startTime2, Title = title2, UserId = userId2 } }); var itemsService = new ItemsService(dataStoreMock.Object); // Act var result = itemsService.GetById(id2.ToString()); // Assert Assert.IsNotNull(result, "result != null"); Assert.AreEqual(description2, result.Description, "Incorrect Description returned"); Assert.AreEqual(endTime2, result.EndTime, "Incorrect EndTime returned"); Assert.AreEqual(id2.ToString(), result.Id, "Incorrect Id returned"); Assert.AreEqual(price2, result.Price, "Incorrect Price returned"); Assert.AreEqual(picturePath2, result.PicturePath, "Incorrect PicturePath returned"); Assert.AreEqual(startTime2, result.StartTime, "Incorrect StartTime returned"); Assert.AreEqual(title2, result.Title, "Incorrect Title returned"); }