public async Task Handle(CreateDatasetVerb verb) { if (string.IsNullOrEmpty(verb.Id)) { verb.Id = Guid.NewGuid().ToString(); } logger.Log($"Creating dataset {verb.Id}"); var emptyDataset = new EmptyDataset(verb.Id); await datasetService.Set(emptyDataset); }
public async Task Dataset_InMemoryCRUD() { var id = "ANewId"; var logger = (TestLogger)Resolve <ILogger>(); var datasetService = Resolve <IDatasetService>(); var createHandler = Resolve <ICreateDatasetHandler>(); var readHandler = Resolve <IReadDatasetHandler>(); var updateHandler = Resolve <IUpdateDatasetHandler>(); var deleteHandler = Resolve <IDeleteDatasetHandler>(); // create var createVerb = new CreateDatasetVerb(); createVerb.Id = id; createHandler.Handle(createVerb).Wait(); var ds = await datasetService.Get <EmptyDataset>(id); Assert.IsNotNull(ds); Assert.AreEqual(ds.Id, id); Assert.AreEqual(ds.Type.Value, DatasetTypes.Empty.Value); // update inline var updateVerb = new UpdateDatasetVerb(); updateVerb.Id = id; updateVerb.Label = "ALabel"; updateVerb.Type = DatasetTypes.SingleClassImage.Value; updateVerb.Url = "http://example.com/pcture.jpeg"; updateHandler.Handle(updateVerb).Wait(); var singleClassDs = await datasetService.Get <SingleClassImageDataset>(id); Assert.IsNotNull(singleClassDs); Assert.AreEqual(singleClassDs.Id, id); Assert.AreEqual(singleClassDs.Type.Value, DatasetTypes.SingleClassImage.Value); // read the data var readVerb = new ReadDatasetVerb(); readVerb.Id = id; readHandler.Handle(readVerb).Wait(); Assert.IsTrue(logger.Messages.Any(m => m.Contains($"{id} is of type {DatasetTypes.SingleClassImage.Value}"))); Assert.IsTrue(logger.Messages.Any(m => m.Contains($"1"))); // delete the dataset var deleteVerb = new DeleteDatasetVerb(); deleteVerb.Id = createVerb.Id; deleteHandler.Handle(deleteVerb).Wait(); await Assert.ThrowsExceptionAsync <DatasetNotFoundException>(() => datasetService.Get <EmptyDataset>(createVerb.Id)); }