public void Check02DecodeListMustBeDtoBad()
        {
            //SETUP

            //ATTEMPT

            var ex = Assert.Throws <InvalidOperationException>(
                () => DecodeToService <ListService> .CreateCorrectService <Post>(WhatItShouldBe.SyncAnyDto, new object[] { null }));

            //VERIFY
            ex.Message.ShouldEqual("This type of service only works with some form of EfGenericDto.");
        }
        public void Check03MustBeSpecificDtoBad()
        {
            //SETUP

            //ATTEMPT

            var ex = Assert.Throws <InvalidOperationException>(
                () => DecodeToService <DetailServiceAsync> .CreateCorrectService <SimplePostDto>(WhatItShouldBe.AsyncSpecificDto, new object[] { null }));

            //VERIFY
            ex.Message.ShouldEqual("This service needs a class which inherited from EfGenericDtoAsync`2.");
        }
        public void Check01DecodeNoSyncAsyncBad()
        {
            //SETUP

            //ATTEMPT

            var ex = Assert.Throws <InvalidOperationException>(
                () => DecodeToService <ListService> .CreateCorrectService <Post>(WhatItShouldBe.DataClass, new object[] { null }));

            //VERIFY
            ex.Message.ShouldEqual("Neither the IsSync or the IsAsync flags were set.");
        }
        public void Check13DecodeDetailDtoAsyncOk()
        {
            //SETUP
            dynamic service;

            //ATTEMPT
            using (new TimerToConsole("Decode"))
                service = DecodeToService <DetailServiceAsync> .CreateCorrectService <SimplePostDtoAsync>(WhatItShouldBe.AsyncAnything, new object[] { null });

            //VERIFY
            ExtendAsserts.ShouldNotEqualNull(service);
            ExtendAsserts.IsA <DetailServiceAsync <Post, SimplePostDtoAsync> >(service);
        }
        public void Check05DecodeListDtoOk()
        {
            //SETUP
            dynamic service;

            //ATTEMPT
            using (new TimerToConsole("Decode"))
                service = DecodeToService <ListService> .CreateCorrectService <SimplePostDto>(WhatItShouldBe.SyncAnything, new object[] { null });

            //VERIFY
            ExtendAsserts.ShouldNotEqualNull(service);
            ExtendAsserts.IsA <ListService <Post, SimplePostDto> >(service);
        }
        public void Check00DecodeListOk()
        {
            //SETUP
            var timer = new Stopwatch();

            //ATTEMPT
            timer.Start();
            var service = DecodeToService <ListService> .CreateCorrectService <Post>(WhatItShouldBe.SyncAnything, new object[] { null });

            timer.Stop();

            //VERIFY
            ExtendAsserts.ShouldNotEqualNull(service);
            ExtendAsserts.IsA <ListService <Post> >(service);
            Console.WriteLine("took {0:f3} ms", 1000.0 * timer.ElapsedTicks / Stopwatch.Frequency);
        }
예제 #7
0
        /// <summary>
        /// This adds a new entity class to the database with error checking
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="newItem">either entity class or dto to create the data item with</param>
        /// <returns>status</returns>
        public async Task <ISuccessOrErrors> CreateAsync <T>(T newItem) where T : class
        {
            var service = DecodeToService <CreateServiceAsync> .CreateCorrectService <T>(WhatItShouldBe.AsyncAnything, _db);

            return(await service.CreateAsync(newItem).ConfigureAwait(false));
        }
예제 #8
0
        /// <summary>
        /// This returns a status which, if Valid, contains a single entry found using its primary keys.
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="keys">The keys must be given in the same order as entity framework has them</param>
        /// <returns>Status. If valid Result holds data (not tracked), otherwise null</returns>
        public ISuccessOrErrors <T> GetDetail <T>(params object[] keys) where T : class, new()
        {
            var service = DecodeToService <DetailService> .CreateCorrectService <T>(WhatItShouldBe.SyncAnything, _db);

            return(service.GetDetail(keys));
        }
        /// <summary>
        /// This returns the dto with any data that is needs for the view setup in it
        /// </summary>
        /// <typeparam name="TDto">The type of the data to output. This must be EfGeneric Dto</typeparam>
        /// <returns>The dto with any secondary data filled in</returns>
        public async Task <TDto> GetDtoAsync <TDto>() where TDto : class
        {
            var service = DecodeToService <CreateSetupServiceAsync> .CreateCorrectService <TDto>(WhatItShouldBe.AsyncSpecificDto, _db);

            return(await service.GetDtoAsync());
        }
예제 #10
0
        /// <summary>
        /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
        /// you need to display the view again with errors
        /// </summary>
        /// <param name="dto">Must be a dto inherited from EfGenericDtoAsync</param>
        /// <returns></returns>
        public T ResetDto <T>(T dto) where T : class
        {
            var service = DecodeToService <UpdateService> .CreateCorrectService <T>(WhatItShouldBe.SyncSpecificDto, _db);

            return(service.ResetDto(dto));
        }
예제 #11
0
        /// <summary>
        /// This updates the data in the database using the input data
        /// </summary>
        /// <typeparam name="T">The type of input data.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="data">data to update the class. If Dto then copied over to data class</param>
        /// <returns></returns>
        public ISuccessOrErrors Update <T>(T data) where T : class
        {
            var service = DecodeToService <UpdateService> .CreateCorrectService <T>(WhatItShouldBe.SyncAnything, _db);

            return(service.Update(data));
        }
예제 #12
0
        /// <summary>
        /// This returns a status which, if Valid, has single entry using the primary keys to find it.
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="keys">The keys must be given in the same order as entity framework has them</param>
        /// <returns>Task with Status. If valid Result holds data (not tracked), otherwise null</returns>
        public async Task <ISuccessOrErrors <T> > GetOriginalAsync <T>(params object[] keys) where T : class
        {
            var service = DecodeToService <UpdateSetupServiceAsync> .CreateCorrectService <T>(WhatItShouldBe.AsyncClassOrSpecificDto, _db);

            return(await service.GetOriginalAsync(keys));
        }
        /// <summary>
        /// This updates the data in the database using the input data
        /// </summary>
        /// <typeparam name="T">The type of input data.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="data">data to update the class. If Dto then copied over to data class</param>
        /// <returns></returns>
        public async Task <ISuccessOrErrors> UpdateAsync <T>(T data) where T : class
        {
            var service = DecodeToService <UpdateServiceAsync> .CreateCorrectService <T>(WhatItShouldBe.AsyncClassOrSpecificDto, _db);

            return(await service.UpdateAsync(data));
        }
예제 #14
0
        /// <summary>
        /// This adds a new entity class to the database with error checking
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="newItem">either entity class or dto to create the data item with</param>
        /// <returns>status</returns>
        public ISuccessOrErrors Create <T>(T newItem) where T : class
        {
            var service = DecodeToService <CreateService> .CreateCorrectService <T>(WhatItShouldBe.SyncAnything, _db);

            return(service.Create(newItem));
        }
        /// <summary>
        /// This returns a status which, if Valid, contains a single entry found using its primary keys.
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="keys">The keys must be given in the same order as entity framework has them</param>
        /// <returns>Status. If valid Result holds data (not tracked), otherwise null</returns>
        public async Task <ISuccessOrErrors <T> > GetDetailAsync <T>(params object[] keys) where T : class, new()
        {
            var service = DecodeToService <DetailServiceAsync> .CreateCorrectService <T>(WhatItShouldBe.AsyncAnything, _db);

            return(await service.GetDetailAsync(keys).ConfigureAwait(false));
        }
        /// <summary>
        /// This returns a status which, if Valid, has single entry using the primary keys to find it.
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or one of the EfGenericDto's</typeparam>
        /// <param name="keys">The keys must be given in the same order as entity framework has them</param>
        /// <returns>Status. If valid Result holds data (not tracked), otherwise null</returns>
        public ISuccessOrErrors <T> GetOriginal <T>(params object[] keys) where T : class
        {
            var service = DecodeToService <UpdateSetupService> .CreateCorrectService <T>(WhatItShouldBe.SyncClassOrSpecificDto, _db);

            return(service.GetOriginal(keys));
        }
예제 #17
0
        /// <summary>
        /// This returns an IQueryable list of all items of the given type
        /// </summary>
        /// <typeparam name="T">The type of the data to output.
        /// Type must be a type either an EF data class or a class inherited from the EfGenericDto or EfGenericDtoAsync</typeparam>
        /// <returns>note: the list items are not tracked</returns>
        public IQueryable <T> GetAll <T>() where T : class, new()
        {
            var service = DecodeToService <ListService> .CreateCorrectService <T>(WhatItShouldBe.SyncAnything, _db);

            return(service.GetAll());
        }
        /// <summary>
        /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
        /// you need to display the view again with errors
        /// </summary>
        /// <param name="dto">Must be a dto inherited from EfGenericDtoAsync</param>
        /// <returns></returns>
        public async Task <T> ResetDtoAsync <T>(T dto) where T : class
        {
            var service = DecodeToService <UpdateServiceAsync> .CreateCorrectService <T>(WhatItShouldBe.AsyncSpecificDto, _db);

            return(await service.ResetDtoAsync(dto));
        }
예제 #19
0
        /// <summary>
        /// This returns the dto with any data that is needs for the view setup in it
        /// </summary>
        /// <typeparam name="TDto">The type of the data to output. This must be EfGeneric Dto</typeparam>
        /// <returns>The dto with any secondary data filled in</returns>
        public TDto GetDto <TDto>() where TDto : class
        {
            var service = DecodeToService <CreateSetupService> .CreateCorrectService <TDto>(WhatItShouldBe.SyncSpecificDto, _db);

            return(service.GetDto());
        }