public void SaveItemAsync_NullItem() { var validator = new Mock <IValidator>(MockBehavior.Strict).Object; var next = new Mock <ISaveItemService <Uom> >(MockBehavior.Strict).Object; var uut = new SaveItemServiceValidate <Uom>(validator, next); Assert.ThrowsAsync <ArgumentNullException> ( async() => await uut.SaveItemAsync(null) ); }
protected ISaveItemService <TItem> BuildSaveItemService <TItem>(IComponentContext context) where TItem : class, IEntity { var httpService = BuildWriteHttpService(context); var serializer = new JsonContentSerializer(); var saveItemServiceBuildRequest = new SaveItemServiceBuildRequest <TItem>(httpService, serializer); var itemUrlBuilder = context.Resolve <IItemWriteUrlBuilder <TItem> >(); var saveItemServiceBuildUrl = new SaveItemServiceBuildUrl <TItem>(itemUrlBuilder, saveItemServiceBuildRequest); var validator = new Validator(); var saveItemServiceValidator = new SaveItemServiceValidate <TItem>(validator, saveItemServiceBuildUrl); return(new SaveItemService <TItem>(saveItemServiceValidator)); }
public async Task SaveItemAsync() { var uom = new Uom(); //var expectedErrorDictionary = new Dictionary<string, ReadOnlyCollection<string>>(); Dictionary <string, ReadOnlyCollection <string> > expectedErrorDictionary = null; var validator = new Mock <IValidator>(MockBehavior.Strict); validator.Setup(v => v.Validate(uom, out expectedErrorDictionary)).Returns(true); var next = new Mock <ISaveItemService <Uom> >(MockBehavior.Strict); next.Setup(n => n.SaveItemAsync(uom)).Returns(Task.CompletedTask); var uut = new SaveItemServiceValidate <Uom>(validator.Object, next.Object); await uut.SaveItemAsync(uom); }
public void SaveItemAsync_InvalidItem() { var uom = new Uom(); var expectedErrorDictionary = new Dictionary <string, ReadOnlyCollection <string> >(); var validator = new Mock <IValidator>(MockBehavior.Strict); validator.Setup(v => v.Validate(uom, out expectedErrorDictionary)).Returns(false); var next = new Mock <ISaveItemService <Uom> >(MockBehavior.Strict).Object; var uut = new SaveItemServiceValidate <Uom>(validator.Object, next); var exception = Assert.ThrowsAsync <BadRequestHttpException> ( async() => await uut.SaveItemAsync(uom) ); Assert.AreEqual(expectedErrorDictionary, exception.ErrorDictionary); }