public void TestRetrieve_Fail() { Mock <IDynamoDBContext> context = new Mock <IDynamoDBContext>(); context.Setup(D => D.LoadAsync <WeighInWeight>(It.IsAny <string>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns((string a, DateTime? b, object c) => { throw new Exception("Test Exception"); }); context.Setup(D => D.LoadAsync <WeighInUser>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns((string a, string b, object c) => { WeighInUser user = new WeighInUser() { UserId = a, FirstName = b, UserKey = "UnitTestKey", StartingWeight = 88.8m, StartingWeightDate = new DateTime(2018, 7, 16) }; return(Task.FromResult <WeighInUser>(user)); }); TestAwsFactory factory = new TestAwsFactory() { DynamoDBContext = context.Object }; using (GetWeight getWeight = new GetWeight(factory)) { WeighInException wEx = Assert.Throws <WeighInException>(() => getWeight.Retrieve("UnitTestId", "Unit", new DateTime(2018, 7, 16))); Assert.That(wEx.Message, Is.EqualTo("Test Exception")); } }
public void TestRetrieve_Fail() { Mock <IDynamoDBContext> context = new Mock <IDynamoDBContext>(); context.Setup(D => D.LoadAsync <WeighInUser>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns((string a, string b, object c) => { throw new Exception("Test Exception"); }); TestAwsFactory factory = new TestAwsFactory() { DynamoDBContext = context.Object }; using (GetUser getUser = new GetUser(factory)) { WeighInException wEx = Assert.Throws <WeighInException>(() => getUser.Retrieve("UnitTestId", "Unit")); Assert.That(wEx.Message, Is.EqualTo("Test Exception")); } }