コード例 #1
0
        public void AWSDynamoDBStore_ConvertToFromStorageFormat_GrainReference_List()
        {
            // NOTE: This test requires Silo to be running & Client init so that grain references can be resolved before serialization.
            Guid[]  ids    = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            IUser[] grains = new IUser[3];
            grains[0] = GrainClient.GrainFactory.GetGrain <IUser>(ids[0]);
            grains[1] = GrainClient.GrainFactory.GetGrain <IUser>(ids[1]);
            grains[2] = GrainClient.GrainFactory.GetGrain <IUser>(ids[2]);

            var initialState = new GrainStateContainingGrainReferences();

            foreach (var g in grains)
            {
                initialState.GrainList.Add(g);
                initialState.GrainDict.Add(g.GetPrimaryKey().ToString(), g);
            }
            var entity  = new GrainStateRecord();
            var storage = new DynamoDBStorageProvider();

            storage.InitLogger(logger);
            storage.ConvertToStorageFormat(initialState, entity);
            var convertedState = (GrainStateContainingGrainReferences)storage.ConvertFromStorageFormat(entity);

            Assert.NotNull(convertedState);
            Assert.Equal(initialState.GrainList.Count, convertedState.GrainList.Count);  // "GrainList size"
            Assert.Equal(initialState.GrainDict.Count, convertedState.GrainDict.Count);  // "GrainDict size"
            for (int i = 0; i < grains.Length; i++)
            {
                string iStr = ids[i].ToString();
                Assert.Equal(initialState.GrainList[i], convertedState.GrainList[i]);       // "GrainList #{0}", i
                Assert.Equal(initialState.GrainDict[iStr], convertedState.GrainDict[iStr]); // "GrainDict #{0}", i
            }
            Assert.Equal(initialState.Grain, convertedState.Grain);                         // "Grain"
        }
コード例 #2
0
        public void AWSDynamoDBStore_ConvertToFromStorageFormat_GrainReference()
        {
            // NOTE: This test requires Silo to be running & Client init so that grain references can be resolved before serialization.
            Guid  id    = Guid.NewGuid();
            IUser grain = GrainClient.GrainFactory.GetGrain <IUser>(id);

            var initialState = new GrainStateContainingGrainReferences {
                Grain = grain
            };
            var entity  = new GrainStateRecord();
            var storage = new DynamoDBStorageProvider();

            storage.InitLogger(logger);
            storage.ConvertToStorageFormat(initialState, entity);
            var convertedState = new GrainStateContainingGrainReferences();

            convertedState = (GrainStateContainingGrainReferences)storage.ConvertFromStorageFormat(entity);
            Assert.NotNull(convertedState);                         // Converted state
            Assert.Equal(initialState.Grain, convertedState.Grain); // "Grain"
        }