Beispiel #1
0
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { new User {
                                                                                           Username = "******"
                                                                                       } })
                };
                StubIdentity            = new Mock <IIdentity>();
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };

                StubIdentity.Setup(stub => stub.IsAuthenticated).Returns(true);
                StubIdentity.Setup(stub => stub.Name).Returns("aUsername");

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);
            }
            public TestableCuratedPackagesController()
            {
                Fakes = new Fakes();

                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };

                SetOwinContextOverride(Fakes.CreateOwinContext());

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
        static Action <object> GetMutator2 <TElement>(PropertyInfo property, FakeEntitiesContext fakeContext)
            where TElement : class
        {
            return(obj =>
            {
                var originalCollection = (ICollection <TElement>)property.GetValue(obj);
                if (originalCollection == null)
                {
                    originalCollection = new Collection <TElement>();
                }

                var mutatedCollection = new ObservableCollection <TElement>(originalCollection);
                mutatedCollection.CollectionChanged +=
                    new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
                        (col, args) =>
                {
                    var set = fakeContext.Set <TElement>();
                    if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                    {
                        foreach (var item in args.NewItems.Cast <TElement>())
                        {
                            set.Add(item);
                        }
                    }
                });
                property.SetValue(obj, mutatedCollection);
            });
        }
Beispiel #4
0
            public TestableCuratedPackagesController()
            {
                StubCuratedFeed = new CuratedFeed
                {
                    Key = 0, Name = "aFeedName", Managers = new HashSet <User>(new[] { Fakes.User })
                };
                StubPackageRegistration = new PackageRegistration {
                    Key = 0, Id = "anId"
                };
                StubPackage = new Package
                {
                    Key = 34,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version = "1.0.0"
                };
                StubLatestPackage = new Package
                {
                    Key = 42,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version      = "2.0.1-alpha",
                    IsLatest     = true,
                    IsPrerelease = true
                };
                StubLatestStablePackage = new Package
                {
                    Key = 41,
                    PackageRegistration    = StubPackageRegistration,
                    PackageRegistrationKey = StubPackageRegistration.Key,
                    Version        = "2.0.0",
                    IsLatestStable = true
                };

                OwinContext = Fakes.CreateOwinContext();

                EntitiesContext = new FakeEntitiesContext();
                EntitiesContext.CuratedFeeds.Add(StubCuratedFeed);
                EntitiesContext.PackageRegistrations.Add(StubPackageRegistration);

                StubPackageRegistration.Packages.Add(StubPackage);
                StubPackageRegistration.Packages.Add(StubLatestPackage);
                StubPackageRegistration.Packages.Add(StubLatestStablePackage);

                var curatedFeedRepository = new EntityRepository <CuratedFeed>(
                    EntitiesContext);

                var curatedPackageRepository = new EntityRepository <CuratedPackage>(
                    EntitiesContext);

                base.CuratedFeedService = new CuratedFeedService(
                    curatedFeedRepository,
                    curatedPackageRepository);

                var httpContext = new Mock <HttpContextBase>();

                TestUtility.SetupHttpContextMockForUrlGeneration(httpContext, this);
            }
Beispiel #5
0
        public FakeDbSet(FakeEntitiesContext fakeEntitiesContext)
        {
            _fakeEntitiesContext = fakeEntitiesContext;
            _data      = new ObservableCollection <T>();
            _queryable = new EnumerableQuery <T>(_data);
            _collectionPropertyMutators = new Dictionary <PropertyInfo, Action <object> >();

            foreach (PropertyInfo property in typeof(T).GetProperties())
            {
                if (property.CanRead && property.CanWrite && property.PropertyType.IsGenericType)
                {
                    var genericType = property.PropertyType.GetGenericTypeDefinition();
                    if (genericType == typeof(ICollection <>))
                    {
                        _collectionPropertyMutators.Add(property, GetMutator(property));
                    }
                }
            }
        }
Beispiel #6
0
        public static void VerifyCommitChanges(this IEntitiesContext self)
        {
            FakeEntitiesContext context = Assert.IsAssignableFrom <FakeEntitiesContext>(self);

            context.VerifyCommitChanges();
        }
 public TestableUserServiceWithDBFaking()
 {
     Config         = (MockConfig = new Mock <IAppConfiguration>()).Object;
     UserRepository = new EntityRepository <User>(FakeEntitiesContext = new FakeEntitiesContext());
 }