示例#1
0
        public void ReopenTest()
        {
            const string arrayName                 = "ReopenPCSMWithSpaceManagerTest";
            const int    elementSize               = 16;
            const int    userHeaderSize            = 8;
            IPersistentCollectionSpaceManager pafs = InitPAFS(arrayName, elementSize, userHeaderSize);

            try
            {
                byte[] userHeader = new byte[userHeaderSize] {
                    1, 2, 3, 4, 5, 6, 7, 8
                };
                pafs.PutUserHeader(userHeader);
                int    index         = 0;
                byte[] expectedBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
                pafs.Put(index, expectedBytes);

                pafs.Close();
                pafs = new PersistentCollectionSpaceManager(arrayName);

                Assert.AreEqual(elementSize, pafs.GetElementSize());
                Assert.AreEqual(userHeaderSize, pafs.GetUserHeaderSize());
                TestHelper.AssertByteArraysAreSame(userHeader, pafs.GetUserHeader());
                TestHelper.AssertByteArraysAreSame(expectedBytes, pafs.Get(index));
            }
            finally
            {
                pafs.Close();
            }
        }
示例#2
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        private IPersistentCollectionSpaceManager InitPAFS(string arrayName, int elementSize, int uHeaderSize)
        {
            PersistentCollectionSpaceManager pcsm;

            try
            {
                pcsm = new PersistentCollectionSpaceManager(arrayName, elementSize, uHeaderSize);
            }
            catch (FileNameConflictException)
            {
                pcsm = new PersistentCollectionSpaceManager(arrayName);
                pcsm.Delete();
                pcsm = new PersistentCollectionSpaceManager(arrayName, elementSize, uHeaderSize);
            }
            return(pcsm);
        }
示例#3
0
        public void CreateTooSmallTest()
        {
            PersistentCollectionSpaceManager pcsm = null;

            try
            {
                pcsm = new PersistentCollectionSpaceManager("PCSMCreateTooSmall", 3, 3);
                Assert.Fail("Should throw an exception");
            } catch (InvalidElementSizeException)
            {
                if (pcsm != null)
                {
                    pcsm.Delete();
                }
            }
        }
示例#4
0
        public void CreateTest()
        {
            //prime the pump
            string arrayName = "arrayName";
            PersistentCollectionSpaceManager pcsm = (PersistentCollectionSpaceManager)InitPAFS(arrayName, 16, 4);

            pcsm.Delete();
            pcsm = null;
            PersistentCollectionSpaceManager pcsm2 = new PersistentCollectionSpaceManager(arrayName, 16, 4);

            try
            {
                pcsm = new PersistentCollectionSpaceManager(arrayName, 16, 4);
                Assert.Fail("Should throw an exception");
            }catch (FileNameConflictException)
            {
                if (pcsm != null)
                {
                    pcsm.Delete();
                }
            }
        }