Beispiel #1
0
        public void ClientModelTest()
        {
            using (var scope = new SharePointEmulationScope(EmulationMode.Enabled))
            {
                // Create shims for the ClientContext class and its base class
                var ctx     = new ShimClientContext();
                var ctxBase = new ShimClientRuntimeContext(ctx);

                var site = new ShimSite();
                var web  = new ShimWeb();

                ctx.SiteGet      = () => { return(site); };
                ctx.WebGet       = () => { return(web); };
                ctx.ExecuteQuery = () => { };

                ImplementLoadFake <Web>(ctxBase);
                ImplementLoadFake <Site>(ctxBase);
                ImplementLoadFake <User>(ctxBase);

                var user          = new ShimUser();
                var userPrincipal = new ShimPrincipal(user);
                userPrincipal.LoginNameGet = () => { return("i:0#.f|membership|[email protected]"); };
                web.CurrentUserGet         = () => { return(user); };
                web.TitleGet = () => { return("Title"); };

                // Test with the ClientContext ctx
                var rCtx = ctx.Instance;
                rCtx.Load(rCtx.Web, w => w.Title);
                rCtx.Load(rCtx.Web.CurrentUser, u => u.LoginName);
                rCtx.ExecuteQuery();

                Assert.That(user.Instance.LoginName, Is.EqualTo("i:0#.f|membership|[email protected]"));
            }
        }
Beispiel #2
0
 private static void ImplementLoadFake <T>(ShimClientRuntimeContext ctxBase) where T : ClientObject
 {
     // Add implementation for ctx.Load<Web>(...)
     ctxBase.LoadOf1M0ExpressionOfFuncOfM0ObjectArray <T>((a, b) => { });
     ctxBase.LoadQueryOf1ClientObjectCollectionOfM0 <T>(delegate { return(null); });
     ctxBase.LoadQueryOf1IQueryableOfM0 <T>(delegate { return(null); });
 }
        public void Adicionar_Pessoa_Sem_SharePoint()
        {
            var nomelista = "Pessoas";

            using (ShimsContext.Create())
            {
                //arrange
                var ctx = new ShimClientContext
                {
                    ExecuteQuery = () => { },
                    WebGet = () => new ShimWeb
                    {
                        ListsGet = () => new ShimListCollection
                        {
                            GetByTitleString = (s) =>
                            {
                                Assert.Equal(nomelista, s);
                                return new ShimList
                                {
                                    TitleGet = () => nomelista,
                                    AddItemListItemCreationInformation = information =>
                                        new ShimListItem
                                    {
                                        Update = () =>
                                        {
                                            //o item foi atualizado
                                            Assert.True(true);
                                        },

                                        ItemSetStringObject = (s1, o) =>
                                        {
                                            //valida se houve uma inserção do item "Title"
                                            //somente Title pode ser inserido
                                            //Assert.Equal(s1, "Title");
                                            Assert.NotNull(o);
                                        }
                                    },
                                    Update = () =>
                                    {
                                        //houve atualizacao
                                        Assert.True(true);
                                    }
                                };
                            }
                        }
                    }
                };

                var ctxRuntime = new ShimClientRuntimeContext(ctx);
                ctxRuntime.LoadOf1M0ExpressionOfFuncOfM0ObjectArray<List>((a, b) => { });
                ctxRuntime.LoadQueryOf1ClientObjectCollectionOfM0<List>(delegate { return null; });
                ctxRuntime.LoadQueryOf1IQueryableOfM0<List>(delegate { return null; });

                ctxRuntime.LoadOf1M0ExpressionOfFuncOfM0ObjectArray<ListItem>((a, b) => { });
                ctxRuntime.LoadQueryOf1ClientObjectCollectionOfM0<ListItem>(delegate { return null; });
                ctxRuntime.LoadQueryOf1IQueryableOfM0<ListItem>(delegate { return null; });

                var repo = new PessoaRepositorio();

                //act
                repo.AdicionarPessoa(new Pessoa{Email = "*****@*****.**", Nome = "lucas"}, ctx);

                //assert
                var result = repo.BuscarPessoa((x=> x.Nome == "lucas" ));

                Assert.NotNull(result);
            }
        }