Beispiel #1
0
        public async Task TestCreate_SocialableEntityDoesNotExist()
        {
            using (ShimsContext.Create())
            {
                System.Data.Entity.Fakes.ShimDbContext.AllInstances.SetOf1 <Organization>((c) =>
                {
                    return(context.Organizations);
                });
                var socialMediaType = new SocialMediaType
                {
                    SocialMediaTypeId   = SocialMediaType.Facebook.Id,
                    SocialMediaTypeName = SocialMediaType.Facebook.Value
                };
                var userId              = 1;
                var id                  = 10;
                var user                = new User(userId);
                var value               = "value";
                var socialMediaTypeId   = socialMediaType.SocialMediaTypeId;
                var socialMediaPresense = new OrganizationSocialMediaPresence(user, socialMediaTypeId, value, id);

                context.SocialMediaTypes.Add(socialMediaType);

                Func <Task> f = () =>
                {
                    return(service.CreateAsync <Organization>(socialMediaPresense));
                };
                service.Invoking(x => x.Create <Organization>(socialMediaPresense)).ShouldThrow <ModelNotFoundException>()
                .WithMessage(String.Format("The sociable entity with id [{0}] was not found.", id));
                f.ShouldThrow <ModelNotFoundException>()
                .WithMessage(String.Format("The sociable entity with id [{0}] was not found.", id));
            }
        }
Beispiel #2
0
        public void TestConstructor()
        {
            var id                = 10;
            var userId            = 1;
            var socialMediaTypeId = SocialMediaType.Facebook.Id;
            var value             = "facebook.com/someone";
            var user              = new User(userId);
            var instance          = new OrganizationSocialMediaPresence(user, socialMediaTypeId, value, id);

            Assert.AreEqual(id, instance.OrganizationId);
            //Assert the base constructor is called.
            Assert.AreEqual(value, instance.Value);
        }
Beispiel #3
0
        public async Task TestCreate_CheckProperties()
        {
            using (ShimsContext.Create())
            {
                System.Data.Entity.Fakes.ShimDbContext.AllInstances.SetOf1 <Organization>((c) =>
                {
                    return(context.Organizations);
                });

                var organization = new Organization
                {
                    OrganizationId = 1
                };

                var socialMediaType = new SocialMediaType
                {
                    SocialMediaTypeId   = SocialMediaType.Facebook.Id,
                    SocialMediaTypeName = SocialMediaType.Facebook.Value
                };
                var userId              = 1;
                var user                = new User(userId);
                var value               = "value";
                var socialMediaTypeId   = socialMediaType.SocialMediaTypeId;
                var socialMediaPresense = new OrganizationSocialMediaPresence(user, socialMediaTypeId, value, organization.GetId());

                context.SetupActions.Add(() =>
                {
                    organization.SocialMedias.Clear();
                    context.SocialMediaTypes.Add(socialMediaType);
                    context.Organizations.Add(organization);
                });

                Action beforeServiceTester = () =>
                {
                    Assert.AreEqual(0, context.SocialMedias.Count());
                    Assert.AreEqual(0, context.Organizations.First().SocialMedias.Count);
                };

                Action <SocialMedia> tester = (serviceResult) =>
                {
                    Assert.IsNotNull(serviceResult);
                    Assert.AreEqual(1, organization.SocialMedias.Count);
                    var firstSocialMedia = context.Organizations.First().SocialMedias.First();
                    Assert.IsTrue(Object.ReferenceEquals(serviceResult, firstSocialMedia));

                    Assert.AreEqual(socialMediaType.SocialMediaTypeId, serviceResult.SocialMediaTypeId);
                    Assert.AreEqual(value, serviceResult.SocialMediaValue);
                    Assert.AreEqual(userId, serviceResult.History.CreatedBy);
                    Assert.AreEqual(userId, serviceResult.History.RevisedBy);
                    DateTimeOffset.Now.Should().BeCloseTo(serviceResult.History.CreatedOn, 2000);
                    DateTimeOffset.Now.Should().BeCloseTo(serviceResult.History.RevisedOn, 2000);
                };

                context.Revert();
                beforeServiceTester();
                var socialMedia = service.Create <Organization>(socialMediaPresense);
                tester(socialMedia);

                context.Revert();
                beforeServiceTester();
                socialMedia = await service.CreateAsync <Organization>(socialMediaPresense);

                tester(socialMedia);
            }
        }