public void IfSuccessTest() { var testObject = 0; try { // Test exception is thrown. Exceptional <int> .Success(0, new PagingInfo(10, 5)).IfSuccess(null); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.AreEqual("action", ex.ParamName); } catch { Assert.Fail(); } Exceptional <int> .Success(0, new PagingInfo(10, 5)).IfSuccess(x => testObject = 5); Assert.AreEqual(5, testObject); Exceptional <int> .Failure(new ArgumentNullException("test")).IfSuccess(x => testObject = 10); Assert.AreNotEqual(10, testObject); }
public void FailureTest() { var testObject = Exceptional <int?> .Failure(new ArgumentNullException("test")); Assert.AreEqual(false, testObject.IsSuccess); Assert.IsInstanceOfType(testObject.Exception, typeof(ArgumentNullException)); Assert.AreEqual("test", ((ArgumentNullException)testObject.Exception).ParamName); }
public void FailureTest() { var testObject = Exceptional <int?> .Failure(new ArgumentNullException("test")); Assert.False(testObject.IsSuccess); Assert.IsType <ArgumentNullException>(testObject.Exception); Assert.Equal("test", ((ArgumentNullException)testObject.Exception).ParamName); }
public void ThenTest() { var testObject = Exceptional <int> .Success(10, new PagingInfo(10, 5)); var mappedObject = testObject.Then(x => Exceptional <int> .Success(x * 2, new PagingInfo(10, 5))); try { // Test exception is thrown. testObject.Then <int>(null); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.AreEqual("function", ex.ParamName); } catch { Assert.Fail(); } testObject .IfSuccess(x => Assert.AreEqual(10, x)) .IfFailure(_ => Assert.Fail()); mappedObject .IfSuccess(x => Assert.AreEqual(20, x)) .IfFailure(_ => Assert.Fail()); testObject = Exceptional <int> .Success(10, new PagingInfo(10, 5)); mappedObject = testObject.Then(x => Exceptional <int> .Failure(new ArgumentNullException("test"))); testObject .IfSuccess(x => Assert.AreEqual(10, x)) .IfFailure(_ => Assert.Fail()); mappedObject .IfSuccess(_ => Assert.Fail()) .IfFailure(x => Assert.IsInstanceOfType(x, typeof(ArgumentException))); testObject = Exceptional <int> .Failure(new ArgumentNullException("test")); mappedObject = testObject.Then(x => Exceptional <int> .Failure(new ArgumentNullException("test"))); testObject .IfSuccess(_ => Assert.Fail()) .IfFailure(x => Assert.IsInstanceOfType(x, typeof(ArgumentException))); mappedObject .IfSuccess(_ => Assert.Fail()) .IfFailure(x => Assert.IsInstanceOfType(x, typeof(ArgumentException))); }
public void Failure_Create_Success() { // arrange var exception = new Exception("my exception"); // act var result = Exceptional <string> .Failure(exception); // assert Assert.False(result.IsSuccess); Assert.Equal(exception, result.Exception); }
public void Map_Failure_Does_Not_Execute_Action() { // arrange var exception = new Exception("my exception"); var testObject = Exceptional <int> .Failure(exception); // act var result = testObject.Map(x => x.ToString()); // assert Assert.IsNotType <string>(result.Value); }
public void IfSuccess_Does_Not_Executes_Action() { // arrange var testResult = 0; var testObject = Exceptional <string> .Failure(new Exception()); // act testObject.IfSuccess(ex => testResult = 10); // assert Assert.Equal(0, testResult); }
public void IfFailure_Executes_Action() { // arrange const int EXPECTED_RESULT = 10; var testResult = 0; var testObject = Exceptional <string> .Failure(new Exception()); // act testObject.IfFailure(ex => testResult = EXPECTED_RESULT); // assert Assert.Equal(EXPECTED_RESULT, testResult); }
public void Then_Failure_Does_Not_Execute_Action() { // arrange var testResult = string.Empty; var testObject = Exceptional <int> .Failure(new Exception()); // act var result = testObject .Then(x => Exceptional <string> .Success("success!!")); // assert Assert.False(result.IsSuccess); }
/// <summary> /// Generates a booster pack for a specific set asynchronously. /// </summary> /// <param name="code">The set code to generate a booster for.</param> /// <returns>A <see cref="Exceptional{List{Card}}"/> representing the result containing a <see cref="List{Card}"/> or an exception.</returns> public async Task <Exceptional <List <Card> > > GenerateBoosterAsync(string code) { try { var url = new Uri(Path.Combine(BuildUri(code).AbsoluteUri, "booster")); var rootCardList = await CallWebServiceGet <RootCardListDto>(url).ConfigureAwait(false); return(Exceptional <List <Card> > .Success(CardService.MapCardsList(rootCardList), MtgApiController.CreatePagingInfo())); } catch (Exception ex) { return(Exceptional <List <Card> > .Failure(ex)); } }
/// <summary> /// Generates a booster pack for a specific set. /// </summary> /// <param name="code">The set code to generate a booster for.</param> /// <returns>A <see cref="Exceptional{List{Card}}"/> representing the result containing a <see cref="List{Card}"/> or an exception.</returns> public Exceptional <List <Card> > GenerateBooster(string code) { try { var url = new Uri(Path.Combine(BuildUri(code).AbsoluteUri, "booster"), UriKind.Absolute); var rootCardList = CallWebServiceGet <RootCardListDto>(url).Result; return(Exceptional <List <Card> > .Success(CardService.MapCardsList(rootCardList), MtgApiController.CreatePagingInfo())); } catch (AggregateException ex) { return(Exceptional <List <Card> > .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Find a specific set by its set code. /// </summary> /// <param name="code">The set code to query for.</param> /// <returns>A <see cref="Exceptional{Set}"/> representing the result containing a <see cref="Set"/> or an exception.</returns> public Exceptional <Set> Find(string code) { try { var rootSet = CallWebServiceGet <RootSetDto>(BuildUri(code)).Result; var model = new Set(rootSet.Set); return(Exceptional <Set> .Success(model, MtgApiController.CreatePagingInfo())); } catch (AggregateException ex) { return(Exceptional <Set> .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets all the <see cref="TModel"/> defined by the query parameters. /// </summary> /// <returns>A <see cref="Exceptional{List{Set}}"/> representing the result containing all the items.</returns> public async override Task <Exceptional <List <Set> > > AllAsync() { try { var query = BuildUri(_whereQueries); var rootSetList = await CallWebServiceGet <RootSetListDto>(query).ConfigureAwait(false); return(Exceptional <List <Set> > .Success(MapSetsList(rootSetList), MtgApiController.CreatePagingInfo())); } catch (Exception ex) { return(Exceptional <List <Set> > .Failure(ex)); } }
/// <summary> /// Find a specific card by its multi verse identifier. /// </summary> /// <param name="id">The identifier to query for.</param> /// <returns>A <see cref="Exceptional{Card}"/> representing the result containing a <see cref="Card"/> or an exception.</returns> public Exceptional <Card> Find(string id) { try { var rootCard = CallWebServiceGet <RootCardDto>(BuildUri(id)).Result; var model = new Card(rootCard.Card); return(Exceptional <Card> .Success(model, MtgApiController.CreatePagingInfo())); } catch (AggregateException ex) { return(Exceptional <Card> .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Find a specific set by its set code. /// </summary> /// <param name="code">The set code to query for.</param> /// <returns>A <see cref="Exceptional{Set}"/> representing the result containing a <see cref="Set"/> or an exception.</returns> public Exceptional <Set> Find(string code) { try { var rootSet = this.CallWebServiceGet <RootSetDto>(this.BuildUri(code)).Result; var model = new Set(rootSet.Set); return(Exceptional <Set> .Success(model)); } catch (AggregateException ex) { return(Exceptional <Set> .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets all the <see cref="TModel"/> defined by the query parameters. /// </summary> /// <returns>A <see cref="Exceptional{List{Set}}"/> representing the result containing all the items.</returns> public override Exceptional <List <Set> > All() { try { var query = BuildUri(_whereQueries); var rootSetList = CallWebServiceGet <RootSetListDto>(query).Result; return(Exceptional <List <Set> > .Success(MapSetsList(rootSetList), MtgApiController.CreatePagingInfo())); } catch (AggregateException ex) { return(Exceptional <List <Set> > .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets all the <see cref="TModel"/> defined by the query parameters. /// </summary> /// <returns>A <see cref="Exceptional{List{Card}}"/> representing the result containing all the items.</returns> public override Exceptional <List <Card> > All() { try { var query = this.BuildUri(this._whereQueries); var rootCardList = this.CallWebServiceGet <RootCardListDto>(query).Result; return(Exceptional <List <Card> > .Success(CardService.MapCardsList(rootCardList))); } catch (AggregateException ex) { return(Exceptional <List <Card> > .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets a list of all the card types. /// </summary> /// <returns>A list of all the card types.</returns> public Exceptional <List <string> > GetCardTypes() { try { var url = new Uri(new Uri(BaseMtgUrl), string.Concat(this.Version.GetDescription(), "/", ApiEndPoint.CardTypes.GetDescription())); var rootTypeList = this.CallWebServiceGet <RootCardTypeDto>(url).Result; return(Exceptional <List <string> > .Success(rootTypeList.Types)); } catch (AggregateException ex) { return(Exceptional <List <string> > .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets a list of all the card types. /// </summary> /// <returns>A list of all the card types.</returns> public async Task <Exceptional <List <string> > > GetCardTypesAsync() { try { var url = new Uri(new Uri(BaseMtgUrl), string.Concat(this.Version.GetDescription(), "/", ApiEndPoint.CardTypes.GetDescription())); var rootTypeList = await this.CallWebServiceGet <RootCardTypeDto>(url).ConfigureAwait(false); return(Exceptional <List <string> > .Success(rootTypeList.Types)); } catch (Exception ex) { return(Exceptional <List <string> > .Failure(ex)); } }
/// <summary> /// Find a specific card by its multi verse identifier. /// </summary> /// <param name="id">The identifier to query for.</param> /// <returns>A <see cref="Exceptional{Card}"/> representing the result containing a <see cref="Card"/> or an exception.</returns> public Exceptional <Card> Find(string id) { try { var rootCard = this.CallWebServiceGet <RootCardDto>(this.BuildUri(id)).Result; var model = new Card(rootCard.Card); return(Exceptional <Card> .Success(model)); } catch (AggregateException ex) { return(Exceptional <Card> .Failure(ex.Flatten().InnerException)); } }
/// <summary> /// Gets all the <see cref="TModel"/> defined by the query parameters. /// </summary> /// <returns>A <see cref="Exceptional{List{Card}}"/> representing the result containing all the items.</returns> public async override Task <Exceptional <List <Card> > > AllAsync() { try { var query = this.BuildUri(this._whereQueries); var rootCardList = await this.CallWebServiceGet <RootCardListDto>(query).ConfigureAwait(false); return(Exceptional <List <Card> > .Success(CardService.MapCardsList(rootCardList))); } catch (Exception ex) { return(Exceptional <List <Card> > .Failure(ex)); } }
/// <summary> /// Find a specific card by its set code. /// </summary> /// <param name="code">The set code to query for.</param> /// <returns>A <see cref="Exceptional{Set}"/> representing the result containing a <see cref="Set"/> or an exception.</returns> public async Task <Exceptional <Set> > FindAsync(string code) { try { var rootSet = await CallWebServiceGet <RootSetDto>(BuildUri(code)).ConfigureAwait(false); var model = new Set(rootSet.Set); return(Exceptional <Set> .Success(model, MtgApiController.CreatePagingInfo())); } catch (Exception ex) { return(Exceptional <Set> .Failure(ex)); } }
/// <summary> /// Find a specific card by its multi verse identifier. /// </summary> /// <param name="id">The identifier to query for.</param> /// <returns>A <see cref="Exceptional{Card}"/> representing the result containing a <see cref="Card"/> or an exception.</returns> public async Task <Exceptional <Card> > FindAsync(string id) { try { var rootCard = await this.CallWebServiceGet <RootCardDto>(this.BuildUri(id)).ConfigureAwait(false); var model = new Card(rootCard.Card); return(Exceptional <Card> .Success(model)); } catch (Exception ex) { return(Exceptional <Card> .Failure(ex)); } }
/// <summary> /// Find a specific card by its set code. /// </summary> /// <param name="code">The set code to query for.</param> /// <returns>A <see cref="Exceptional{Set}"/> representing the result containing a <see cref="Set"/> or an exception.</returns> public async Task <Exceptional <Set> > FindAsync(string code) { try { var rootSet = await this.CallWebServiceGet <RootSetDto>(this.BuildUri(code)).ConfigureAwait(false); var model = new Set(rootSet.Set); return(Exceptional <Set> .Success(model)); } catch (Exception ex) { return(Exceptional <Set> .Failure(ex)); } }
/// <summary> /// Find a specific card by its multi verse identifier. /// </summary> /// <param name="id">The identifier to query for.</param> /// <returns>A <see cref="Exceptional{Card}"/> representing the result containing a <see cref="Card"/> or an exception.</returns> public async Task <Exceptional <Card> > FindAsync(string id) { try { var rootCard = await CallWebServiceGet <RootCardDto>(BuildUri(id)).ConfigureAwait(false); var model = new Card(rootCard.Card); return(Exceptional <Card> .Success(model, MtgApiController.CreatePagingInfo())); } catch (Exception ex) { return(Exceptional <Card> .Failure(ex)); } }
/// <inheritdocs /> public async Task <Exceptional <IList <BoardGameSearch> > > SearchAsync() { try { var url = _apiProvider.BuildUri(ApiEndPoint.Search, _whereQueries); var rootList = await _apiProvider .CallWebServiceGetAsync <BoardGameListDto>(url) .ConfigureAwait(false); var result = rootList?.BoardGames .Select(x => _modelFactory.CreateBoardGameSearch(x)) .ToList(); return(Exceptional <IList <BoardGameSearch> > .Success(result)); } catch (Exception ex) { return(Exceptional <IList <BoardGameSearch> > .Failure(ex)); } }
public void MapTest() { var testObject = Exceptional <int> .Success(10, new PagingInfo(10, 5)); var mappedObject = testObject.Map(x => x * 2); try { // Test exception is thrown. testObject.Map <int>(null); Assert.True(false); } catch (ArgumentNullException ex) { Assert.Equal("function", ex.ParamName); } catch { Assert.True(false); } testObject .IfSuccess(x => Assert.Equal(10, x)) .IfFailure(_ => Assert.True(false)); mappedObject .IfSuccess(x => Assert.Equal(20, x)) .IfFailure(_ => Assert.True(false)); testObject = Exceptional <int> .Failure(new ArgumentNullException("test")); mappedObject = testObject.Map(x => x * 2); testObject .IfSuccess(_ => Assert.True(false)) .IfFailure(x => Assert.IsType <ArgumentNullException>(x)); mappedObject .IfSuccess(_ => Assert.True(false)) .IfFailure(x => Assert.IsType <ArgumentNullException>(x)); }