Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        /// <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));
            }
        }
Exemplo n.º 11
0
        /// <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));
            }
        }
Exemplo n.º 12
0
        /// <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));
            }
        }
Exemplo n.º 13
0
        /// <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));
            }
        }
Exemplo n.º 14
0
        /// <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));
            }
        }
Exemplo n.º 15
0
        /// <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));
            }
        }
Exemplo n.º 16
0
        /// <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));
            }
        }
Exemplo n.º 17
0
        /// <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));
            }
        }
Exemplo n.º 18
0
        /// <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));
            }
        }
Exemplo n.º 19
0
        /// <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));
            }
        }
Exemplo n.º 20
0
        /// <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));
            }
        }
Exemplo n.º 21
0
        /// <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));
            }
        }
Exemplo n.º 22
0
        /// <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));
            }
        }
Exemplo n.º 23
0
        /// <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));
            }
        }
Exemplo n.º 24
0
        /// <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));
            }
        }
Exemplo n.º 25
0
        /// <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));
            }
        }
Exemplo n.º 26
0
        /// <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));
            }
        }
Exemplo n.º 27
0
        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));
        }