示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateTheFileIfOverwriting() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncateTheFileIfOverwriting()
        {
            // GIVEN
            IdContainer.CreateEmptyIdFile(_fs, _file, 30, false);
            IdContainer idContainer = new IdContainer(_fs, _file, 5, false);

            idContainer.Init();
            for (int i = 0; i < 17; i++)
            {
                idContainer.FreeId(i);
            }
            idContainer.Close(30);
            assertThat(( int )_fs.getFileSize(_file), greaterThan(IdContainer.HeaderSize));

            // WHEN
            IdContainer.CreateEmptyIdFile(_fs, _file, 30, false);

            // THEN
            assertEquals(IdContainer.HeaderSize, ( int )_fs.getFileSize(_file));
            assertEquals(30, IdContainer.ReadHighId(_fs, _file));
            idContainer = new IdContainer(_fs, _file, 5, false);
            idContainer.Init();
            assertEquals(30, idContainer.InitialHighId);

            idContainer.Close(30);
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldForceStickyMark() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForceStickyMark()
        {
            // GIVEN
            CreateEmptyFile();

            // WHEN opening the id generator, where the jvm crashes right after
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();

            // THEN
            try
            {
                IdContainer.ReadHighId(_fs, _file);
                fail("Should have thrown, saying something with sticky generator");
            }
            catch (InvalidIdGeneratorException)
            {
                // THEN Good
            }
            finally
            {
                idContainer.Close(0);
            }
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFalseOnInitIfTheFileWasCreated()
        public virtual void ShouldReturnFalseOnInitIfTheFileWasCreated()
        {
            // When
            // An IdContainer is created with no underlying file
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            // Then
            // Init should return false
            assertFalse(idContainer.Init());
            idContainer.Close(100);
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void idContainerReadWriteBySingleByte() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IdContainerReadWriteBySingleByte()
        {
            SingleByteFileSystemAbstraction fileSystem = new SingleByteFileSystemAbstraction();
            IdContainer idContainer = new IdContainer(fileSystem, _file, 100, false);

            idContainer.Init();
            idContainer.Close(100);

            idContainer = new IdContainer(fileSystem, _file, 100, false);
            idContainer.Init();
            assertEquals(100, idContainer.InitialHighId);
            fileSystem.Dispose();
            idContainer.Close(100);
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeleteIfClosed()
        public virtual void ShouldDeleteIfClosed()
        {
            // GIVEN
            CreateEmptyFile();
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();
            idContainer.Close(0);

            // WHEN
            idContainer.Delete();

            // THEN
            assertFalse(_fs.fileExists(_file));
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnTrueOnInitIfAProperFileWasThere()
        public virtual void ShouldReturnTrueOnInitIfAProperFileWasThere()
        {
            // Given
            // A properly created and closed id file
            IdContainer idContainer = new IdContainer(_fs, _file, 100, false);

            idContainer.Init();
            idContainer.Close(100);

            // When
            // An IdContainer is created over it
            idContainer = new IdContainer(_fs, _file, 100, false);

            // Then
            // init() should return true
            assertTrue(idContainer.Init());
            idContainer.Close(100);
        }