Beispiel #1
0
        public async Task Update_NotFound_Async()
        {
            var updateItem = new TestItemBare();

            updateItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default);
            await CrudStorage.UpdateAsync(CrudHelper.CreateNewId <TId>(), updateItem);

            Assert.Fail("Expected an exception");
        }
Beispiel #2
0
        public async Task Update_ValidationFailed_Async()
        {
            var id = await CreateItemAsync(TypeOfTestDataEnum.Default);

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEqual(default(TId), id);
            var updatedItem = new TestItemValidated <TId>();

            updatedItem.InitializeWithDataForTesting(TypeOfTestDataEnum.ValidationFail);
            await CrudStorage.UpdateAsync(id, updatedItem);

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.Fail($"Expected the method {nameof(CrudStorage.UpdateAsync)} to detect that the data was not valid and throw the exception {nameof(FulcrumContractException)}.");
        }
        protected async Task PrepareStorageAsync(Guid id, TModel storageValue)
        {
            if (storageValue == null)
            {
                await CrudStorage.DeleteAsync(id);
            }
            else
            {
                var value = await CrudStorage.ReadAsync(id);

                if (value == null)
                {
                    await CrudStorage.CreateWithSpecifiedIdAsync(id, storageValue);
                }
                else if (!Equals(value, storageValue))
                {
                    await CrudStorage.UpdateAsync(id, storageValue);
                }
            }
        }